[英]Set the Button Text according to Resource File in Visual Studio 2013
I am an Amateur Visual C# Programmer. 我是一名业余Visual C#程序员。 I want to implement the concept of I18N in my project. 我想在我的项目中实现I18N的概念。 (Similar to strings.xml in Android) (类似于Android中的strings.xml )
I have added 2 String Resources in my Resource File. 我在资源文件中添加了2个字符串资源。
And I have added 2 Buttons in my form. 我在表单中添加了2个按钮。 Now, I want the text of the Button to be the string value from the Resource file. 现在,我希望Button的文本成为Resource文件中的字符串值。
Please help. 请帮忙。
Adhish Adhish
If you are using windows form, you can use this procedure. 如果您使用的是Windows窗体,则可以使用此过程。
Open the properties menu of the form in the design. 在设计中打开表单的属性菜单。 Select the option "Language" and choose the language that you want. 选择选项“语言”,然后选择所需的语言。
Selecting a different language will create automatically a new file resource with the label for the language selected. 选择其他语言将自动创建带有所选语言标签的新文件资源。
The file .resx will the same name of the form plus the initial of the language used. 文件.resx将具有与表单相同的名称以及所用语言的缩写。
It really depends on your UI framework. 它确实取决于您的UI框架。 The following solution is for WinForms, but you can implement it (without MVVM) in WPF as well. 以下解决方案适用于WinForms,但您也可以在WPF中实现它(不使用MVVM)。
Your code should look something like this: 您的代码应如下所示:
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = MyResources.ButtonText;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.