bucketman bucketman - 1 year ago 81
C# Question

How to minimize a single Windows application form in C#

I have two forms, Form1 and Form2. I currently have a button in the startup form(Form1) that loads up Form2. What I would like to do is have Form1 become minimized and only show Form2 once it is told to load so that Form1 is not in the background while Form 2 is shown.

So far I have tried things such as:

this.WindowState = FormWindowState.Minimized;

but the problem I'm having is that it causes Form2 to become minimized as well. Is there a way to specifically cause only Form1 to be affected or work around this problem?

below you will find my code, I may have made some mistakes!

Form2 add = new Form2();
this.WindowState = FormWindowState.Minimized;

I had also tried putting the windowstate behind the showdialog but it may not work because it will only execute after the dialog is done working.

Answer Source

Your issue is due to two things.

  1. You're using ShowDialog which launches Form2 as a modal dialog. Hint: Go read about modal dialogs
  2. You need to minimize after showing Form2

Change your code to this:

var add = new Form2();
WindowState = FormWindowState.Minimized;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download