简体   繁体   中英

c# reset a textbox.text property at runtime to use default

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.
}

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.
}

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);

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