Problem with using TopMost property

T

TheJediMessiah

Hi,

I am having a few problems with using the TopMost property for dialogs.
The problem centers around the fact that I have a main dialog which as
a central map and at certain positions on this map I need to display
small message boxs to represent information regarding this point. These
message boxs are simple forms with a ew text fields and labels.
The problem I am having is that I need to set the TopMost property of
the forms to true if I want to see more than one message at a time.

I am creating these message forms dynamically when the user clicks the
correct positon on the main map. What happens is that after the first
message form, the second one makes the first one disappear under the
main form.
If I set the TopMost property then they all appear but when I minimise
the main form, the message dialogs remain on the desktop.

if (e.Button == MouseButtons.Left)
{
Point pt = new Point(e.X, e.Y);
foreach(IconDetails icon in icons)
{
Point pt1 = icon.GetLocation();
Rectangle rect = new Rectangle( pt1.X, pt1.Y, 30, 30);
if (rect.Contains(pt))
{
VMSSiteObject vmsObj =
vmsSiteObjects.GetBySCN(icon.GetDescription());
if (vmsObj != null)
{
ArrayList listOfDisp = (ArrayList)vmsObj.VMSDisplayObjects;
ArrayList disp = (ArrayList)listOfDisp[0];
int mods = disp.Count;
site = new siteDlg(vmsObj);
sz.Width = site.Size.Width - 8;
if (mods > 1)
sz.Height = site.Size.Height + ((mods-1) * 8);
else
sz.Height = site.Size.Height;
}
break;

if (site != null)
{
site.Tag = icon.GetDescription();
siteDlgs.Add(site);
site.Show();
site.Size = sz;
}
}
}
}


Is there another way I could show these forms without having to set the
TopMost property.
 
S

Stoitcho Goutsev \(100\)

TheJediMessiah,

Don't use the parameterless overload of the Show method.
Rather call

form.Show(mainForm);

This way the main form will be the owner of the small forms and they will
stay infront of it and minimize along.
 
S

Stoitcho Goutsev \(100\)

Yes, there are two overloads of the Form's Show method.
This is for .NET 2.0 only thought.
For .NET 1.x you need to set the form's owner property to be the main form
 

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