[英]How to set text to a disabled textbox?
i have a Textbox and some RadioButtons in C#.我在 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:您可以根据文本框是否启用来更改PasswordChar
属性:
TextBox1.PasswordChar = TextBox1.Enabled ? '\0' : '*';
The \0
character will show the contents in plain text. \0
字符将以纯文本形式显示内容。
See this answer for similar results.有关类似结果,请参见此答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.