0

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

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

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
user1963864
  • 69
  • 2
  • 2
  • 4

5 Answers5

10
myTextbox.Visible = !myTextbox.Visible;
Austin Brunkhorst
  • 20,704
  • 6
  • 47
  • 61
4

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;
Austin Henley
  • 4,625
  • 13
  • 45
  • 80
3

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;
}
fa wildchild
  • 2,557
  • 2
  • 15
  • 12
1

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();
   }
}
Codeman
  • 12,157
  • 10
  • 53
  • 91
1
textbox.visible=true;

you should try this on buttonClick event

Haider Khattak
  • 567
  • 3
  • 8
  • 32