资源简介

在Winform中,使用XML文件实现多语言切换(简体中文,繁体中文,英文),可以同时切换所有打开的窗口的语言,程序对可能出现的异常情况都进行了处理,具有更好的性能

资源截图

代码片段和文件信息

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

namespace MultiLanguageDeluxexml
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender EventArgs e)
        {
            //设置combobox的值
            string language = MultiLanguage.GetDefaultLanguage();
            if (language == “ChineseSimplified“)
            {
                languageTxt.Text = “简体中文(默认)“;
            }
            else if (language == “Chinese“)
            {
                languageTxt.Text = “繁體中文“;
            }
            else if (language == “English“)
            {
                languageTxt.Text = “English“;
            }
        }

        private void languageTxt_SelectedIndexChanged(object sender EventArgs e)
        {
            languageTxt.Enabled = false;
            if (languageTxt.Text == “简体中文(默认)“)
            {
                //加载语言包
                ChangeLanguage(“ChineseSimplified“);
            }
            else if (languageTxt.Text == “繁體中文“)
            {
                //加载语言包
                ChangeLanguage(“Chinese“);
            }
            else if (languageTxt.Text == “English“)
            {
                //加载语言包
                ChangeLanguage(“English“);
            }
            languageTxt.Enabled = true;
        }

        //加载默认语言
        private void ChangeLanguage(string language)
        {
            string result = ““;
            //修改默认语言
            if (MultiLanguage.SetDefaultLanguage(language out result))
            {
                //对所有打开的窗口加载默认语言
                foreach (Form form in Application.OpenForms)
                {
                    if (!MultiLanguage.LoadLanguage(form out result))
                    {
                        MessageBox.Show(result + “\r\n程序当前语言可能异常,如果影响正常使用请重新启动程序“ “加载语言“ + form.Name + “(“ + form.Text + “)“ MessageBoxButtons.OK MessageBoxIcon.Error);
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show(result “默认语言“ MessageBoxButtons.OK MessageBoxIcon.Error);
            }
        }

        private void passwordBtn_Click(object sender EventArgs e)
        {
            PasswordForm pwdform = new PasswordForm();
            pwdform.Show();
        }

        private void loginBtn_Click(object sender EventArgs e)
        {
            System.Diagnostics.Process.Start(“http://blog.csdn.net/softimite_zifeng“);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-07 17:20  MultiLanguageDeluxexml\
     目录           0  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\
     文件         279  2017-01-07 18:49  MultiLanguageDeluxexml\MultiLanguageDeluxexml\App.config
     目录           0  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Languages\
     文件        1013  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Languages\Chinese.xml
     文件        1015  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Languages\ChineseSimplified.xml
     文件        1027  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Languages\English.xml
     文件        7187  2017-01-07 18:41  MultiLanguageDeluxexml\MultiLanguageDeluxexml\LoginForm.Designer.cs
     文件        3018  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\LoginForm.cs
     文件        5817  2017-01-07 18:41  MultiLanguageDeluxexml\MultiLanguageDeluxexml\LoginForm.resx
     文件       14983  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\MultiLanguage.cs
     文件        4760  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\MultiLanguageDeluxexml.csproj
     文件        7310  2017-01-07 18:41  MultiLanguageDeluxexml\MultiLanguageDeluxexml\PasswordForm.Designer.cs
     文件        1037  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\PasswordForm.cs
     文件        6571  2017-01-07 18:41  MultiLanguageDeluxexml\MultiLanguageDeluxexml\PasswordForm.resx
     文件         538  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Program.cs
     目录           0  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Properties\
     文件        1368  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Properties\AssemblyInfo.cs
     文件        2896  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Properties\Resources.Designer.cs
     文件        5612  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Properties\Resources.resx
     文件        1109  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Properties\Settings.Designer.cs
     文件         249  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\Properties\Settings.settings
     目录           0  2017-01-07 17:20  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\
     目录           0  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\
     目录           0  2017-01-07 18:49  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\Languages\
     文件        1013  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\Languages\Chinese.xml
     文件        1015  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\Languages\ChineseSimplified.xml
     文件        1027  2017-01-07 18:39  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\Languages\English.xml
     文件       19456  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\MultiLanguageDeluxexml.exe
     文件         279  2017-01-07 18:49  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\MultiLanguageDeluxexml.exe.config
     文件       44544  2017-01-07 19:10  MultiLanguageDeluxexml\MultiLanguageDeluxexml\bin\Debug\MultiLanguageDeluxexml.pdb
............此处省略22个文件信息

评论

共有 条评论