使文本框可见/不可见c#

时间:2013-01-10 02:48:59

标签: c# winforms visible

我正在使用Windows窗体应用程序,我有一个按钮,其中包含textbox

按下按钮时,应使textbox可见并隐藏。

5 个答案:

答案 0 :(得分:8)

myTextbox.Visible = !myTextbox.Visible;

答案 1 :(得分:2)

你试过Google吗?

textBox1.Visible = false;

您可以通过执行以下操作切换可见性:

if(textBox1.Visible == true)
    textBox1.Visible = false;
else
    textBox1.Visible = true;

答案 2 :(得分:2)

的WinForm:

private void button1_Click(object sender, System.EventArgs e)
{
    textBox.Visible = !textBox.Visible;
}

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

答案 3 :(得分:1)

您可以找到示例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();
   }
}

答案 4 :(得分:0)

textbox.visible=true;

您应该在按钮Click事件

上尝试此操作