Newuser
Newuser

Reputation: 399

How to make textbox appear only after user clicks button in c#

How would I make a textbox appear only after clicking a button. THis means that It should be hidden, and once user clicks, then it can appear.

 private void button7_Click(object sender, EventArgs e)
 {
        // .. what next?      
 }

Upvotes: 2

Views: 4401

Answers (2)

Stefan
Stefan

Reputation: 17658

Assuming you have defined a TextBox textBox1 somewhere:

private void button7_Click(object sender, EventArgs e)
{
    textBox1.Visible = !textBox1.Visible;      
}

This way you can toggle the visibility.

You can set it just to true if you like, but make sure the initial Visible state, you can set it in the designer, is false.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564413

You can use Control.Visible to make any control visible or hidden:

private void button7_Click(object sender, EventArgs e)
{
    theTextBox.Visible = true;
}

Just set it's Visible property to false initially (ie: in the designer).

Upvotes: 3

Related Questions