C# Winform程序本地化应用

1. 创建一个WinForm应用程序 – “WindowsFormsLocalizationTest”.

2. 在主窗体属性栏里,把Localizable属性设置成”True”.

3. 添加两个Button:

  Button1->Text = "button1"

  Button2->ID = "btnConfirm", Text = "Confirm"

4. 把窗体的”Language”属性设置成”Chinese” (Simplified Chinese)

5. 修改Button1的Text属性为“确定”

6. Button1的Click事件添加如下代码把当前Culture设置为简体中文:

        private void button1_Click(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
            resources.ApplyResources(this.btnConfirm, "btnConfirm");
        }

7. 项目结构如下图

    

运行程序并点击"button1"按钮,此时btnConfirm的 文字就由“Confirm”转变成“确认”:

在Winform程序中使用资源文件MSDN有以下建议:

In general, you should use forms-based resources for all resources specific to a form in your Windows Forms application. You should use project resources for all non-forms-based user interface strings and images, such as error messages.

即对于窗体要使用窗体资源文件,对于其他所有非窗体资源使用项目资源文件。

参考:

http://code.msdn.microsoft.com/CSWinFormLocalization-59675a87

http://msdn.microsoft.com/en-us/library/y99d1cd3.aspx

  

原文地址:https://www.cnblogs.com/silverbullet11/p/3243859.html