如何本地化基于Windows的程序

时间:2017-06-25 14:09:41

标签: c#

我使用一个组合框,用户可以选择使用英语或波斯语。并通过button1 click更改语言。但有时这种语言更改无法正常工作。

我尝试过:

private void button1_Click(object sender, EventArgs e)
{
    System.Globalization.CultureInfo cul;
    if (comboBox1.SelectedIndex == 0)
    {
        cul = new CultureInfo("en-US");
        Properties.Settings.Default.lan = "en";
        Properties.Settings.Default.Save();
    }
    else if (comboBox1.SelectedIndex == 1)
    {
        cul = new CultureInfo("fa-IR");
        Properties.Settings.Default.lan = "fa";
        Properties.Settings.Default.Save();
    }
    Application.Restart();
}

在程序中我编写了以下命令:

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    System.Globalization.CultureInfo cu;
    if (Properties.Settings.Default.lan == "fa")
        cu = new CultureInfo("fa-R");
    else
        cu = new CultureInfo("en-US");
    System.Threading.Thread.CurrentThread.CurrentCulture = cu;
    System.Threading.Thread.CurrentThread.CurrentUICulture = cu;
    Application.Run(new Form1());
}

0 个答案:

没有答案