【问题标题】:How to get a value of a resource string from a resx file depending of the selected language? [duplicate]如何根据所选语言从 resx 文件中获取资源字符串的值? [复制]
【发布时间】:2023-04-07 20:37:01
【问题描述】:

我有两个 .resx 文件,Form1.fr-FR.resxForm1.en-US.resx。 在这个文件中,我添加了不同的字符串(两个 .resx 的名称相同),每个字符串都有一个取决于 .resx 文件的值。 示例

对于Form1.fr-FR.resx

Name | Value
string1 | bonjour
string2 | aurevoir

对于Form1.en-US.resx

Name | Value
string1 | hello
string2 | bye

我希望根据选择的语言,当我按下按钮时,texbox 会打印 string1 的值。 因此,如果我的表单是 FR,它会打印“bonjour”,如果它是 EN,它会打印“hello”。 如果它可以是极简的代码,那就太好了

谢谢

【问题讨论】:

标签: c# winforms resx


【解决方案1】:

好的,谢谢你的链接,这很好用

private void button1_Click(object sender, EventArgs e)
{
    ResourceManager rm = new System.Resources.ResourceManager(typeof(Form1));
    textBox1.Text = rm.GetString("string1").ToString();
}

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多