How to display second form?

B

Brett Romero

My application start like this:

frmMaster MainForm = new frmMaster();
System.Windows.Forms.Application.Run(MainForm);

The flow is that MainForm shows then a SecondForm shows after the user
does something. This is an MDI app so SecondForm needs to always be
inside MainForm. There are times I need to automatically load the app
and display second form. I'm not sure how that is done. If I do:

frmMaster MainForm = new frmMaster();
frmSecond SecondForm = new frmSecond (someobject);
System.Windows.Forms.Application.Run(SecondForm);
MainForm.Show();
SecondForm.Show();

MainForm is never displayed and SecondForm loads by itself. No
processing needs to take place on MainForm when SecondForm loads
automatically, as in the above code. How can I get SecondForm loaded
inside the MainForm MDI?

Thanks,
Brett
 
S

Stoitcho Goutsev \(100\)

Brett,

Just move creating and showing the second form in the first form constructor
or as a response to the Load event. .NET 2.0's forms also has one very
usefull event - "Shown" that fould be a good place for that. BTW Shown can
be easily implemented in .NET 1.x using Control.BeginInvoke
 
B

Brett Romero

Got it! Thanks.

I'm doing this in first form's constructor:

frmSecondForm secondForm = new frmSecondForm (someobject);
secondForm .Show();
secondForm .BringToFront();

but the second form always ends up behind the first. I even put
BringToFront() in the second form's constructor. I tried focus() as
well. No dice.

Any ideas how I can get the second form to the front?

Thanks,
Brett
 
B

Brett Romero

Sorry. These are MDI forms. So:

frmSecondForm secondForm = new frmSecondForm (someobject);
secondForm .MdiParent = this;
secondForm .Show();

which works.

Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top