Application.Run and ShowDialog (modal dialog on top of main form)



Suppose I create a very simple Windows Forms application, consisting of
a main form, Form1, with a (modal) dialog form, Form2, intended to
appear on top of the main form.

static void Main()
Application.Run(new Form1());
Form2 myForm2 = new Form2();

My problem is this:
When I run my app, Form2 appears to be hidden beneath/behind Form1.
(i.e., Only Form1 is visible. If I quit the app, I can momentarily see
Form2 beneath/behind Form1.)

My question is: Why is this behavior occurring?



possible reasons

1 you may have Alwaysontop turned on for the form1

2 ShowDialog only creates dialogbox it needs to know how to position it
this can be done in the windows form design mode or manually via code before
you call the ShowDialog funtion

also you can try to set form2 to be always on top.



Hi Raj,

Thanks for your reply.

I tried setting TopMost to False for Form1 and setting TopMost to True
for Form2, but that still didn't appear to have any effect.

I believe the issue has to do with the specifics of how Application.Run
works, and I need to learn more about the details on this.

However, if anybody has any other ideas here, please let me know.


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