用vs2005建了一个winform的工程, 在工程里添加了资源文件(包括好几个国家)存储字符串资源. 在显示的时候,发现de的资源取不出来. 用vs2003建了一个同样的工程,却没有问题. 请问是怎么回事呢?目录结构:
Form1.cs
welcome.resx
welcome.ar.resx
welcome.en.resx
welcome.fr.resx
welcome.de.resx工程默认命名空间(即资源文件命名空间)是LanguageResoure, 下面是主要代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private ResourceManager resource; private void Form1_Load(object sender, EventArgs e)
{
resource = new ResourceManager("LanguageResoure.welcome", Assembly.GetExecutingAssembly());
comboBox1.Items.Clear();
comboBox1.Items.Add("en");
comboBox1.Items.Add("fr");
comboBox1.Items.Add("ar");
comboBox1.Items.Add("de");
} private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(comboBox1.Text))
{
MessageBox.Show("please choose a country");
return;
}
CultureInfo ci = new CultureInfo(comboBox1.Text);
label1.Text = resource.GetString("GoodMorning", ci);
label2.Text = resource.GetString("GoodAfternoon", ci);
}
}
每个资源文件都存储了GoodMorning和GoodAfternoon两个字符串资源, 当然值不相同. 选择的时候, 显示的是welcome.resx里存的值, 这是因为取不到welcome.de.resx里的资源, 所以回退到默认资源文件.
在vs2003下没有这个问题, 有知道为什么的兄弟吗?
Form1.cs
welcome.resx
welcome.ar.resx
welcome.en.resx
welcome.fr.resx
welcome.de.resx工程默认命名空间(即资源文件命名空间)是LanguageResoure, 下面是主要代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private ResourceManager resource; private void Form1_Load(object sender, EventArgs e)
{
resource = new ResourceManager("LanguageResoure.welcome", Assembly.GetExecutingAssembly());
comboBox1.Items.Clear();
comboBox1.Items.Add("en");
comboBox1.Items.Add("fr");
comboBox1.Items.Add("ar");
comboBox1.Items.Add("de");
} private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(comboBox1.Text))
{
MessageBox.Show("please choose a country");
return;
}
CultureInfo ci = new CultureInfo(comboBox1.Text);
label1.Text = resource.GetString("GoodMorning", ci);
label2.Text = resource.GetString("GoodAfternoon", ci);
}
}
每个资源文件都存储了GoodMorning和GoodAfternoon两个字符串资源, 当然值不相同. 选择的时候, 显示的是welcome.resx里存的值, 这是因为取不到welcome.de.resx里的资源, 所以回退到默认资源文件.
在vs2003下没有这个问题, 有知道为什么的兄弟吗?
CultureInfo ci = new CultureInfo(comboBox1.Text);
之前从新给ResourceManager指定一下它的Type参数
那应该是VS2003与2005版本对某些组件的兼容性问题.
de-de
German - Austria
de-at
German - Liechtenstein
de-li
German - Luxembourg
de-lu
German - Switzerland
de-ch
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/882ca1eb-81b6-4a73-839d-154c6440bf70.asp
de LCID: 7
de-DE LCID:1031
MARK JF ~