Re: Form.TopMost behaviour by Chris
Chris
Wed Sep 20 08:32:25 CDT 2006
mabster wrote:
> Chris Dunaway wrote:
> > mabster wrote:
> >
> >> There's another property, less well-documented, called TopLevel which
> >> sets the form as topmost only within the current application.
> >
> > Umm.... No.
> >
> >>From the docs:
> >
> > A top-level form is a window that has no parent form, or whose parent
> > form is the desktop window. Top-level windows are typically used as the
> > main form in an application.
>
> I don't know how to respond to that. Did you test it? Make an
> application with a Form1 and Form2, and drop two Buttons on Form1:
>
> private void button1_Click(object sender, EventArgs e)
> {
> Form2 f2 = new Form2();
> f2.TopMost = true;
> f2.Show();
> }
>
> private void button2_Click(object sender, EventArgs e)
> {
> Form2 f2 = new Form2();
> f2.TopLevel = true;
> f2.Show();
> }
>
> TopMost is topmost across the whole system. TopLevel is only "stay on
> top" within the application.
>
> The behaviour is just as I described.
When I clicked button1, Form2 appeared and was above all other forms as
expected. When I clicked button2, Form2 appeared again and seemed to
be above form1, but when I clicked form1, form2 was in the background
and not on top, I saw no special behavior. I added a third button with
this code:
private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.TopLevel = false;
f2.Parent = this;
f2.Show();
}
And the new form appeared *inside* form1 but was not necessarily on top
of other forms in the app.
I can only go by what the docs say and they do not mention anything
about z order in conjunction with the TopLevel property. TopLevel
refers to parentage and not z-order. In fact the default for all forms
is TopLevel = true.
If I am wrong about this, I hope someone with more knowledge will
elaborate.
Cheers,
Chris