2

When I try to Maximize a Form when it is in a Minimized state, (I am using Windows Form) It will not open. Can't figure why.

Here is an example of what I'm doing:

Button_X_Click(args, Events e)
{
  Form1.ActiveForm.WindowState = WindowState.Minimized;

  DialogResult dr = MessageBox.Show
  (
  this, 
  "Would you like to open Form?",
  "Title",
  MessageBoxButtons.YesNo
  )

  if (dr == System.Windows.Forms.DialogResult.Yes)
  {
    Form1.ActiveForm.WindowState =
           FormWindowState.Maximized;
    MessageBox.Show("Done"); //For Testing
  }

Somehow, it does not open my Form. It does show me the "Done" MessageBox.

Could use some help here ;)

user2982172
  • 21
  • 1
  • 2

2 Answers2

0

You need to have a reference to the form you are trying to manipulate. I am expecting to see something like:

    form1.WindowState = FormWindowState.Maximized;

If this code is on the current form you are designing, then I am expecting to see something like:

    this.WindowState = FormWindowState.Maximized;

A bit more context would be helpful.

Eugène
  • 676
  • 5
  • 10
  • guess you were right, Form1.ActiveForm = null. but i can only add ref to Form1.ActiveForm or Form.ActiveForm both are null at minimized state – user2982172 Nov 12 '13 at 08:27
  • The Form1 object being null is another issue. If you add full code of what you are trying to achieve, we can help you more effectively. – Eugène Nov 12 '13 at 09:11
0

Anyway this will work for you:

void Button_X_Click(object args, Events e) {
   Form f = Form1.ActiveForm;
   Form1.ActiveForm.WindowState = WindowState.Minimized;
   DialogResult dr = MessageBox.Show( this,  "Would you like to open Form?",
                                     "Title", MessageBoxButtons.YesNo );
   if (dr == System.Windows.Forms.DialogResult.Yes) {
     f.WindowState = FormWindowState.Maximized;
     MessageBox.Show("Done"); //For Testing
   }
}

NOTE: The arguments of your Button_X_Click have something wrong, I just corrected it a little without caring too much about what Events is, in fact I think you mean EventArgs.

King King
  • 61,710
  • 16
  • 105
  • 130