使文本框可见/不可见 C#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14250082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making text box visible/unvisible c#
提问by user1963864
I'm working on a windows form application and I have a button and a textbox
in it.
我正在开发一个 Windows 窗体应用程序,其中有一个按钮和一个textbox
。
When the button is pressed, it should make the textbox
visible and hidden.
当按钮被按下时,它应该使textbox
可见和隐藏。
回答by Austin Brunkhorst
myTextbox.Visible = !myTextbox.Visible;
回答by Codeman
回答by Austin Henley
Did you try Google?
你试过谷歌吗?
textBox1.Visible = false;
You can toggle the visibility by doing:
您可以通过执行以下操作来切换可见性:
if(textBox1.Visible == true)
textBox1.Visible = false;
else
textBox1.Visible = true;
回答by fa wildchild
WinForm:
WinForm:
private void button1_Click(object sender, System.EventArgs e)
{
textBox.Visible = !textBox.Visible;
}
WPF:
WPF:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox.Visibility != System.Windows.Visibility.Hidden)
textBox.Visibility = System.Windows.Visibility.Hidden;
else
textBox.Visibility = System.Windows.Visibility.Visible;
}
回答by Haider Khattak
textbox.visible=true;
you should try this on buttonClick event
你应该在 buttonClick 事件上试试这个