用最简单有效的办法实现Winform的全球化多国语言版本软件

     因为本身技术很菜,所以很复杂的问题总喜欢找最简单的解决方法,所以我就用最简单的方法实现软件的多国语言版,首先创建winform工程,设置所有的界面元素Text属性为一种语言版本。注意:添加删除控件必须在默认的语言版本中进行。

    在Form表单的属性中有一组设置本地化的属性:

  • Localizable:true   确定是否生成本地化的代码
  • Language:Default    指示当前本地化语言

    切换language为另一种语言 如:英语(美国)en-US  后再重新编辑所有界面元素的Text属性为这个版本的语言,对于Messagebox推荐使用form来创建。

    编辑好后运行程序,则会自动生成下面两个资源文件。

  • Form1.resx
  •  Form1.en-US.resx

 程序源码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Threading;//
using System.Globalization;//
using ControXML;//

   

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            //读取配置
            ControXMLClass cxc = new ControXMLClass("SetApp.xml");
            string lang = cxc.ReadXML("appset", "lang");
            //设置方法
            this.Controls.Clear();
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
            InitializeComponent();
        }

        private void 中文ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //设置方法
            this.Controls.Clear();
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("");
            InitializeComponent();
            //写入配置
            ControXMLClass cxc = new ControXMLClass("SetApp.xml");
            cxc.WriteXML ("appset", "lang","");
        }

        private void 英文ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //设置方法
            this.Controls.Clear();
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            InitializeComponent();
            //写入配置
            ControXMLClass cxc = new ControXMLClass("SetApp.xml");
            cxc.WriteXML("appset", "lang", "en-US");
        }
    }
}

  

上面引用的ControXML命名空间为一个读取XML配置文件的类,别让大家迷糊了,具体参照:http://www.cnblogs.com/mane/archive/2010/11/19/1881400.html

原文地址:https://www.cnblogs.com/mane/p/1939183.html