471,318 Members | 3,236 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

How to display second form?

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

Jan 26 '06 #1
3 16215
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

--
HTH
Stoitcho Goutsev (100)

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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

Jan 26 '06 #2
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

Jan 26 '06 #3
Sorry. These are MDI forms. So:

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

which works.

Brett

Jan 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by TG | last post: by
reply views Thread by yasker | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.