chhff 发表于 2013-2-7 03:45:59

Winform 国际化

using System;using System.Collections.Generic;using System.Text;using System.Reflection;using System.Resources;using System.Threading;using System.Globalization;using System.Windows.Forms;namespace TestLanguage{    public class SelectLanguage    {      public SelectLanguage()      {      }      private string formName;      public ResourceManager GetCurrentCulture()      {            //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");            ResourceManager rm = new ResourceManager("TestLanguage.Resource1", Assembly.GetExecutingAssembly());            return rm;      }      public System.Drawing.Bitmap GetImage(string strObjectId)      {            ResourceManager rm = GetCurrentCulture();            object obj = rm.GetObject(strObjectId);            return (System.Drawing.Bitmap)obj;      }      public string getMsg(string strId)      {            ResourceManager rm = GetCurrentCulture();            CultureInfo ci = Thread.CurrentThread.CurrentCulture;            return rm.GetString(strId, ci);      }      public void SetLanguage(System.Windows.Forms.Control control)      {            //MessageBox.Show(control.GetType().BaseType.Name);            if (control.GetType().BaseType.Name == "Form")            {                formName = control.Name;                control.Text = getMsg(control.Name);            }            for (int i = 0; i < control.Controls.Count; i++)            {                //MessageBox.Show(control.Controls.GetType().Name + "-" + control.Controls.Name);                switch (control.Controls.GetType().Name)                {                  case "Label":                  case "Button":                  case "CheckBox":                  case "LinkLabel":                        control.Controls.Text = getMsg(formName + control.Controls.Name);                        break;                  case "Panel":                        SetLanguage(control.Controls);                        break;                  case "TabControl":                        TabControl tbc = (TabControl)control.Controls;                        for (int j = 0; j < tbc.TabCount; j++)                        {                            tbc.TabPages.Text = getMsg(formName + tbc.TabPages.Name);                            SetLanguage(tbc.TabPages);                        }                        break;                  default:                        break;                }            }      }    }}
页: [1]
查看完整版本: Winform 国际化