简体   繁体   中英

Set the Button Text according to Resource File in Visual Studio 2013

I am an Amateur Visual C# Programmer. I want to implement the concept of I18N in my project. (Similar to strings.xml in Android)

I have added 2 String Resources in my Resource File.

And I have added 2 Buttons in my form. Now, I want the text of the Button to be the string value from the Resource file.

Please help.

Adhish

If you are using windows form, you can use this procedure.
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.

It really depends on your UI framework. The following solution is for WinForms, but you can implement it (without MVVM) in WPF as well.

  1. Create a button in the designer.
  2. Register to the Load event of the form by double clicking it. (Right click on the form => properties => click the events button => search for the Load event)
  3. In the load event, initialize the text of the button with the string from the resources.

Your code should look something like this:

private void Form1_Load(object sender, EventArgs e)
{
    button1.Text = MyResources.ButtonText;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM