如何在窗口窗体字符串中本地化内联字符串
本文关键字:字符串 本地化 窗体 窗口 | 更新日期: 2023-09-27 18:32:53
我想本地化我的 C# Windows 窗体应用程序。我通过逐个设置控件的语言和值来处理本地化控件上的字符串,我有 form1.en.resx 和 form1.fr.resx,当我运行时它按预期工作(法语在法语 pc 的英语在英语 pc's)。但是我找不到如何对代码中的其他字符串执行此操作。假设我有:
MessageBox.Show("Hello world");
我相信我需要类似的东西
MessageBox.Show(Resources.Helloworld);
根据 pc 的语言,它应该像其他控制文本一样选择严格的资源值。做这样的事情到底是什么?
我尝试了Move to resource
选项的磨刀器。但它只移动到项目的资源,因此我无法在其上指定任何语言选项。
任何帮助将不胜感激。
你可以尝试这样的事情:
public enum myResource
{
HelloWorld,
ByeWorld
}
public string GetText(myResource someRes)
{
string sText = "";
switch (someRes)
{
case someRes.HelloWorld:
sText = "Hello World";
break;
case someRes.ByeWorld:
sText = "ByeWorld";
break;
default:
sText = "Empty...";
break;
}
return sText ;
}