简体   繁体   中英

How to set text to a disabled textbox?

i have a Textbox and some RadioButtons in C#.

Now i want to set a Text to a disabled Textbox.

What i tried:

private void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
    TextBox1.Text = "****";
    TextBox1.Enabled = false;
}

This way i cant see the Text.

If i enable the Textbox, the TextBox shows me the String (****)

What can i do to set a Text to a disabled Textbox?

private void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
        textBox1.Enabled = true;
        textBox1.Text = "*****";
        textBox1.ReadOnly = true;
        textBox1.Enabled = false;
    this.Invalidate(); //to perform form re-draw
}

You can change the PasswordChar property based on whether or not the textbox is enabled:

TextBox1.PasswordChar = TextBox1.Enabled ? '\0' : '*';

The \0 character will show the contents in plain text.

See this answer for similar results.

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