如何将文本设置为禁用的文本框?

我在C#中有一个文本框和一些RadioButtons。

现在我想将文本设置为禁用的文本框。

我尝试过的事情:

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

这样我看不到文本。

如果启用了文本框,则文本框会向我显示字符串(****)

如何将文本设置为禁用的文本框?

xinkaikou 回答:如何将文本设置为禁用的文本框?

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

您可以根据是否启用了文本框来更改PasswordChar属性:

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

\0字符将以纯文本形式显示内容。

有关类似结果,请参见this answer

本文链接:https://www.f2er.com/3152219.html

大家都在问