如何启用,禁用c#中的文本框? [英] how to enable, disable textbox in c#?
本文介绍了如何启用,禁用c#中的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何启用,使用Windows窗体禁用c#中的文本框?
i search n发现这个
how to enable, disable textbox in c# using windows form?
i search n found this
textbox.Enabled = false;
但这不起作用,文本框仍然启用
but this is not working,the textbox remains enable
推荐答案
没有不是真的。
当你设置TextBox.Enabled = false
时,TextBox不会与用户交互。 TextBox仍然可见,通过代码,您可以为其分配一个新值。
请参阅 TextBox.Enabled [ ^ ]和如何在C#中锁定文本框 [ ^ ]
No that is not true.
When you setTextBox.Enabled = false
, the TextBox will not "interact" with the user. The TextBox is still visible and via code you can assign a new value to it.
Please see TextBox.Enabled[^] and How to Lock Text Boxes in C#[^]
int checker;
private void btnHideTextBox_Click((object sender, EventArgs e)
{
if (checker%2 == 0)
myTextBox.Enabled = false;
else
myTextBox.Enabled = true;
checker++;
}
试试这个............
Try this............
即使Enabled确实有效 - 我同意它没有''看起来,但我没有测试那么多 - 它可能会混淆用户,因为它看起来仍然应该工作。
相反,使用ReadOnly属性 - 也会使背景灰显,以便用户获得一个他无法输入信息的视觉提示。
Even if Enabled did work - which I agree it doesn''t appear to, but I haven''t tested that much - it would probably confuse the user because it would still look like it should work.
Instead, use the ReadOnly property - that also grays the background so the user gets a visual cue that he can''t enter information.
这篇关于如何启用,禁用c#中的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文