1

In my application i have a lot of support for different languages(WinForms).

Initially i have set the text in the button to say "Start" in a bunch of different languages. On a click-event the text changes to "⚫".

And then i have another button that stops the event on click.

Is it possible to revert the "running" (⚫) text to the original text?

textbox.text.ResetText() just clears it.

private void btnStartTest_Click(object sender, EventArgs e)
{
    btnStartTest.Text="⚫";
}

private void btnStopTest_Click(object sender, EventArgs e)
{
   //reset the text to what it used to be.
}
Joel
  • 5,732
  • 4
  • 37
  • 65
  • 1
    Save the text before you change it & restore from the saved copy ?? – PaulF May 24 '18 at 13:54
  • @PaulF you're correct.. – Joel May 24 '18 at 13:58
  • Easy when you think about it. If you have multiple buttons an alternative would be to create a derived Button class with an extra field - access it via the sender parameter. – PaulF May 24 '18 at 14:02
  • Do you decide what the text for Start is in each language in your code directly or do you use the internationalization mechanism of WinForms using resource files? – NineBerry May 24 '18 at 14:04
  • @NineBerry Internal. However, it would be nice if i could also change the "⚫" to a local language string saying "running" also. – Joel May 24 '18 at 14:07
  • @Joel What does "Internal" mean? – NineBerry May 24 '18 at 14:08
  • How to use internationalization for strings is explained here: https://stackoverflow.com/questions/1142802/how-to-use-localization-in-c-sharp – NineBerry May 24 '18 at 14:09

2 Answers2

0

Solution:

private string languageString;
private void btnStartTest_Click(object sender, EventArgs e)
{
    languageString = btnStartTest.Text;
    btnStartTest.Text="⚫";
}

private void btnStopTest_Click(object sender, EventArgs e)
{
   btnStartTest.Text = languageString;
   //reset the text to what it used to be.
}
Joel
  • 5,732
  • 4
  • 37
  • 65
0

If you use the internationalization mechanism of WinForms that uses resource files to store the property values of controls for different languages, you can use this source code to reset the button to its initial state using the current UI language:

ComponentResourceManager resources = new ComponentResourceManager(typeof(MyFormClass));
resources.ApplyResources(buttonStart, buttonStart.Name);
NineBerry
  • 26,306
  • 3
  • 62
  • 93