0

I have this project for school which requires me to use 2 forms, but I can't have both of them open at the same time.

This means when I open one form, the other one minimizes. When you close this one, I'd like to make it so that the minimized one is restored.

This is what I have now for minimizing it:

private void Mkbtn1_Click(object sender, EventArgs e)
{
    var newForm = new form1();
    newForm.Show();
    this.WindowState = FormWindowState.Minimized;
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Luna
  • 3
  • 3
  • Is there a question in your description? Forms have events that you can use to detect changes in their minimize/maximize state (in particular the `Resize` event, and looking at the `FormWindowState` property). Take a look at https://stackoverflow.com/questions/1052913/how-to-detect-when-a-windows-form-is-being-minimized. Then, get a reference to the other form in each form. When Form1 is minimized, restore Form2 and vice-versa (or something similar depending on exactly what you want to do). – Flydog57 Feb 26 '19 at 17:34
  • @Flydog57 I want to make it so when i Close form2 (fully close it) then form 1 would go full screen again (so a restore to what it was) – Luna Feb 26 '19 at 17:36
  • Look at the FormClosing event on Form2. You will need to have a reference to your form1 object – Flydog57 Feb 26 '19 at 17:56
  • @Flydog57 that is the thing, it doesnt close, it just minimizes, i want the 1st one to open as i close the 2nd one – Luna Feb 26 '19 at 19:03

1 Answers1

0

In form1, which is opening the form2 do things like this

    `private void button1_Click(object sender, EventArgs e)
    {
        Form2 newofrm = new Form2();
        newofrm.parentForm = this;
        newofrm.Show();
        this.Hide();
    }`

And then in form2 use this

   `private void Form2_Resize(object sender, EventArgs e)
    {
        if (WindowState == FormWindowState.Minimized && parentForm != null)
        {
            // Do some stuff
            parentForm.Show();
        }
    }`

Here parentForm is public member of form2 of type Form, also if you want this do be done when form is closed then add form closing event and add same code in the event handler

Anil
  • 318
  • 1
  • 3
  • 13