0

I am learning windows forms and can create a one form with textboxes and stuff, but I was wondering how can I change the form upon let's say clicking a button?, so for instance my initial form has a textbox and a button, if the button is clicked I want to show a form with a dropdown and a button. SO the question should be:

1) How do I change the form upon clicking a button but without creating a new instance of the form.

2) If I wanted, how can I add a form when the button is clicked showing the same drop down and button as a pop up form?

In reality I would like to know both cases, changing the form via using the same form and via popping a new form on top.

Should the questions not be clear, I am willing to further explain

Thank you

1
  • do u mean adding new control to the current form like a dropdown? Commented Jun 13, 2011 at 16:22

1 Answer 1

1

I'm assuming you already know how to add controls in the form designer and how to implement event handlers.

Question 1

private void button1_Click(object sender, EventArgs e)
{
    if (comboBox1.Visible)
    {
        comboBox1.Visible = false;
        textBox1.Visible = true;
    }
    else
    {
        comboBox1.Visible = true;
        textBox1.Visible = false;
    }
}

The button click handler simply toggles the visibility of the two controls.

Question 2

private void button2_Click(object sender, EventArgs e)
{
    Form1 form = new Form1();
    form.ShowDialog();
}

This time the button handler instantiates a new form an then shows it as a modal dialog. Call Show() if you don't want to show modally.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.