XtraGrid控件汉化(C#)

首先应该在程序前面加上using DevExpress.XtraGrid.Localization; 然后自己写一个类如下(我只汉化了我需要的部分,还有很多都没写,要汉化其他的只要找到对应的属性然后返回相应的字符串即可)
public class ChzLocalizer :DevExpress.XtraGrid.Localization.GridLocalizer

             public override string GetLocalizedString(DevExpress.XtraGrid.Localization.GridStringId id)
           {
                switch(id)
                {
                     case GridStringId.CustomFilterDialogCancelButton:return "取消"; 
                     case GridStringId.CustomFilterDialogCaption:return "查询列名:";
                     case GridStringId.CustomFilterDialogConditionBlanks:return "空值";
                     case GridStringId.CustomFilterDialogConditionEQU:return "=等于";
                     case GridStringId.CustomFilterDialogConditionGT:return ">大于";
                     case GridStringId.CustomFilterDialogConditionGTE:return ">=大于等于"; 
                     case GridStringId.CustomFilterDialogConditionLike:return "包含";
                     case GridStringId.CustomFilterDialogConditionLT:return "<小于";
                     case GridStringId.CustomFilterDialogConditionLTE:return "<=小于等于";
                     case GridStringId.CustomFilterDialogConditionNEQ:return "!=不等于"; 
                     case GridStringId.CustomFilterDialogConditionNonBlanks:return "非空";
                     case GridStringId.CustomFilterDialogConditionNotLike:return "不包含";
                     case GridStringId.CustomFilterDialogOkButton:return "确定";
                     case GridStringId.CustomFilterDialogRadioAnd:return "与";
                     case GridStringId.CustomFilterDialogRadioOr:return "或";
                     case GridStringId.CustomFilterDialogFormCaption:return "自定义查询";
                     case GridStringId.PopupFilterNonBlanks:return "非空";
                     case GridStringId.PopupFilterCustom:return "自定义";
                     case GridStringId.PopupFilterBlanks:return "空值";
                     case GridStringId.MenuGroupPanelFullExpand:return "全部展开";
                     case GridStringId.MenuGroupPanelFullCollapse:return "全部收缩"; 
                     case GridStringId.MenuGroupPanelClearGrouping:return "清除分组";
                     case GridStringId.PopupFilterAll:return "全部";
                     case GridStringId.MenuColumnSortAscending:return "按升序排列";
                     case GridStringId.MenuColumnSortDescending:return "按降序排列";
                     case GridStringId.MenuColumnUnGroup:return "取消分组";
                     case GridStringId.MenuColumnClearFilter:return "取消查询";
                     case GridStringId.MenuColumnBestFitAllColumns:return "自动调整列宽(所有列)"; 
                     case GridStringId.MenuColumnBestFit:return "自动调整列宽";
                     case GridStringId.MenuColumnGroupBox:return "分组工具栏";
                     case GridStringId.MenuColumnGroup:return "按此列分组";
                     case GridStringId.MenuColumnColumnCustomization:return "自定义显示";
                     case GridStringId.MenuFooterAverage:return "平均";
                     case GridStringId.MenuFooterCount:return "计数";
                     case GridStringId.MenuFooterMax:return "最大值";
                     case GridStringId.MenuFooterMin:return "最小值";
                     case GridStringId.MenuFooterSum:return "总计";
                     case GridStringId.ColumnViewExceptionMessage:return "是否继续编辑此行";
               }
        return base.GetLocalizedString (id);
      }

写完类以后在程序加载的时候要设置激活代码如下
DevExpress.XtraGrid .Localization.GridLocalizer.Active=new ChzLocalizer();
DevExpress的其他控件的汉化方法大体都和汉化XtraGrid一样,每个控件都有自己相应的Localizer只要做同样的事情就可以了.

你可能感兴趣的:(C#)