这是多语言的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsMultiLanguage
{
public partial class Form1 : Form
{
ResourceManager m_resourceManger;
public Form1()
{
InitializeComponent();
m_resourceManger = new ResourceManager("WindowsFormsMultiLanguage.Localization", Assembly.GetExecutingAssembly());
// Init UICulture to CurrentCulture
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
// Init Controls
UpdateUIControls();
}
private void UpdateUIControls()
{
try
{
if (m_resourceManger != null)
{
this.label1.Text = m_resourceManger.GetString("test1");
this.label2.Text = m_resourceManger.GetString("test2");
}
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
}
private void OnLanguageChange(object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
string culture = string.Empty;
switch (radioButton.Text)
{
case "French - France (fr-FR)":
culture = "fr-FR";
break;
case "U.S. English (en-US)":
culture = "en-US";
break;
}
// This is used for the language of the user interface
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
}
}
}
我收到一条错误消息,此时无法解析资源项 test&, test2:
this.label1.Text = m_resourceManger.GetString("test1");
this.label2.Text = m_resourceManger.GetString("test2");
我添加了 2 个资源文件 1 个用于英语,第二个用于法语,我不知道是什么错误..
![在此处输入图像描述][1] ![在此处输入图像描述][2]