TopMost Form And A Dialog Box Created From A Static Method

G

Gary Brown

Hi,

I have a dialog box that must behave as MessageBox does
with regard to the TopMost property. It must be TopMost if
and only if the calling form is TopMost. A static method
creates the dialog box. Is there a way of determining if the
application is TopMost from a static method?

There are some inelegant workarounds but I would prefer to
do whatever MessageBox does.

Thanks,
Gary
 
M

mpetrotta

Hi,

I have a dialog box that must behave as MessageBox does
with regard to the TopMost property. It must be TopMost if
and only if the calling form is TopMost. A static method
creates the dialog box. Is there a way of determining if the
application is TopMost from a static method?

There are some inelegant workarounds but I would prefer to
do whatever MessageBox does.

One way you could do this is to stash your main form in a static
property, and retrieve that property from your static method:

return MyMainForm.Instance.TopMost;

You could also cycle through all open forms, looking for your main
form:

foreach (Form f in Application.OpenForms)
{
if (f is MyMainForm)
{
return f.TopMost;
}

Michael
 

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