六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 42|回复: 0

Winform 国际化

[复制链接]

升级  42%

5

主题

5

主题

5

主题

童生

Rank: 1

积分
21
 楼主| 发表于 2013-2-7 03:45:59 | 显示全部楼层 |阅读模式
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[i].GetType().Name + "-" + control.Controls[i].Name);                switch (control.Controls[i].GetType().Name)                {                    case "Label":                    case "Button":                    case "CheckBox":                    case "LinkLabel":                        control.Controls[i].Text = getMsg(formName + control.Controls[i].Name);                        break;                    case "Panel":                        SetLanguage(control.Controls[i]);                        break;                    case "TabControl":                        TabControl tbc = (TabControl)control.Controls[i];                        for (int j = 0; j < tbc.TabCount; j++)                        {                            tbc.TabPages[j].Text = getMsg(formName + tbc.TabPages[j].Name);                            SetLanguage(tbc.TabPages[j]);                        }                        break;                    default:                        break;                }            }        }    }}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表