-1

I am trying to do speech recognition for my application. I have the Speech Recognition form (Form2) and my main form (Form1). I want to find a way to maximize Form1 from Form2. I have already learned about speech recognition and I don't need help with that, but any help with this problem would be greatly appreciated!

//Form1
public void Maximize()
{
this.WindowState = FormWindowState.Maximized;
}


//Form2
private void Maximize_Form1()
{
Form1 form = new Form1();
form.Maximize();
}

I have tried the "Show" way, but that makes a whole new window. Please Help.
Thank You.

Nicholas Hein
  • 119
  • 1
  • 11

2 Answers2

1

You need to give a reference to the existing Form1 instance to your Form2 instance, so it can do WindowState = FormWindowState.Maximized; on it. For example:

class Form2 {

    private Form1 form1Ref;

    public void setForm1(Form1 f) { form1ref = f};

}

Form1 would call setForm1(this) on the form2 instance, which could then use form1ref to maximize form1.

In your current code, you are creating a new Form1 instance, which is totally independent from the previous instance.

Alexander Gessler
  • 45,603
  • 7
  • 82
  • 122
0

you are using this.WindowState from From2, I would suggest you to pass a parameter to Maximize() method.

From Form2 when you execute the Maximize() method it considers Form2 in reference.

To pass the reference of Form1 you should send the object to Method and set the required property.

//Form1
public void Maximize(Form frmForm)
{
frmForm.WindowState = FormWindowState.Maximized;
}


//Form2
private void Maximize_Form1()
{
Form1 form = new Form1();
form.Maximize(form);
}
Murtaza
  • 3,045
  • 2
  • 25
  • 39
  • 1
    Don't try to make another instance of `Form1` within `Form2`. You got to use same object of main form which was created. – Hassan Aug 21 '14 at 05:39