Form question

ok, I have a button in form1 that opens form 2 once form2 is open can I make it so the button can't be pressed while form2 is open

Then how do I get a button that is in form2 close the form2

Thanks


Answer this question

Form question

  • Arran Siu

    You can do this by creating a couple of properties and methods on the two forms, like the following:

    public class Form1
    {
    public void Form2Done()
    {
    OpenForm2Button.Enabled = true;
    }

    private void OpenForm2Button_Click(object sender, EventArgs e)
    {
    OpenForm2Button.Enabled = false;
    Form2 form = new Form2();
    form.OpeningForm = this;
    form.Show();
    }
    }

    public class Form2
    {
    public Form1 OpeningForm;

    private void Form2_OnClosing(object sender, EventArgs e)
    {
    if (OpeningForm != null)
    OpeningForm.Form2Done();
    }
    }

    Naturally, you'll have to hook up the events to the event handlers that I've created.

    Hope that helps.



  • John Sorensen

    Thanks that worked out just the way i wanted it

    Thanks
    Jon

  • Form question