使文本框可见/不可见 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:10:10  来源:igfitidea点击:

Making text box visible/unvisible c#

c#winformsvisible

提问by user1963864

I'm working on a windows form application and I have a button and a textboxin it.

我正在开发一个 Windows 窗体应用程序,其中有一个按钮和一个textbox

When the button is pressed, it should make the textboxvisible and hidden.

当按钮被按下时,它应该使textbox可见和隐藏。

回答by Austin Brunkhorst

myTextbox.Visible = !myTextbox.Visible;

回答by Codeman

You can find an example here

你可以在这里找到一个例子

private void button1_Click(object sender, System.EventArgs e)
{
   /* If the CTRL key is pressed when the 
      * control is clicked, hide the control. */ 
   if(Control.ModifierKeys == Keys.Control)
   {
      ((Control)sender).Hide();
   }
}

回答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 事件上试试这个