I'm a bit confused regarding the behaviour when setting the Form.TopMost
property. If setting the property to 'true', does it make the form top-most
of all windows in all applications, or only the form's application ?
Searching google, I've found people claiming it's enough to set TopMost in
order for the form to be top-most of all windows in the system, and other say
that a call to Win API's SetWindowPos (with HWND_TOPMOST as a parameter) is
needed.

So, which is correct?

Re: Form.TopMost behaviour by mabster

mabster
Sun Sep 17 18:47:46 CDT 2006

Yonatan wrote:
> I'm a bit confused regarding the behaviour when setting the Form.TopMost
> property. If setting the property to 'true', does it make the form top-most
> of all windows in all applications, or only the form's application ?
> Searching google, I've found people claiming it's enough to set TopMost in
> order for the form to be top-most of all windows in the system, and other say
> that a call to Win API's SetWindowPos (with HWND_TOPMOST as a parameter) is
> needed.
>
> So, which is correct?

TopMost sets the form to be the topmost form across the entire system.

There's another property, less well-documented, called TopLevel which
sets the form as topmost only within the current application.

(IIRC)

Re: Form.TopMost behaviour by Michael

Michael
Mon Sep 18 00:10:38 CDT 2006

"Yonatan" <Yonatan@discussions.microsoft.com> wrote in message
news:CE48FA73-4A02-4C2D-BE1F-7D78F898F4D1@microsoft.com...
> I'm a bit confused regarding the behaviour when setting the Form.TopMost
> property. If setting the property to 'true', does it make the form
> top-most
> of all windows in all applications, or only the form's application ?
> Searching google, I've found people claiming it's enough to set TopMost in
> order for the form to be top-most of all windows in the system, and other
> say
> that a call to Win API's SetWindowPos (with HWND_TOPMOST as a parameter)
> is
> needed.
>
> So, which is correct?

Dunno, you could have tried it quicker than writing this message.



Re: Form.TopMost behaviour by Chris

Chris
Tue Sep 19 15:39:52 CDT 2006

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.


Re: Form.TopMost behaviour by mabster

mabster
Tue Sep 19 18:49:21 CDT 2006

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.

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


Re: Form.TopMost behaviour by mabster

mabster
Wed Sep 20 16:12:22 CDT 2006

Chris Dunaway wrote:
> 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.

Run it again but switch away from the application when it's running.

After clicking button1, Form2 will stay on top even when another
application has focus.

After clicking button2, Form2 will always be on top of Form1 but will
not stay on top of other applications.

As I said - TopMost is system-wide stay-on-top, but TopLevel is only
application-wide.

Re: Form.TopMost behaviour by Chris

Chris
Wed Sep 20 16:43:59 CDT 2006

mabster wrote:
> Chris Dunaway wrote:
> > 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.
>
> Run it again but switch away from the application when it's running.
>
> After clicking button1, Form2 will stay on top even when another
> application has focus.
>

Yes.

> After clicking button2, Form2 will always be on top of Form1 but will
> not stay on top of other applications.

Not if I click Form1 first before switching away. In that case, the
first Form2 stays on top because it is TopMost but the second Form2
does *not* stay on top of Form1. Setting TopLevel=true when creating
the second form2 is redundant as the form is already TopLevel.
TopLevel has nothing to do with z-order.


Re: Form.TopMost behaviour by mabster

mabster
Wed Sep 20 18:38:17 CDT 2006

Chris Dunaway wrote:

>> After clicking button1, Form2 will stay on top even when another
>> application has focus.
>>
>
> Yes.
>
>> After clicking button2, Form2 will always be on top of Form1 but will
>> not stay on top of other applications.
>
> Not if I click Form1 first before switching away. In that case, the
> first Form2 stays on top because it is TopMost but the second Form2
> does *not* stay on top of Form1. Setting TopLevel=true when creating
> the second form2 is redundant as the form is already TopLevel.
> TopLevel has nothing to do with z-order.

Oh, you made Form1 TopMost as well? I was only talking about a single
"stay-on-top" form in an app. Any more than one is just asking for
trouble, UI-wise, I think.

Re: Form.TopMost behaviour by Michael

Michael
Wed Sep 20 18:51:54 CDT 2006

"mabster" <mabster@madprops.org> wrote in message
news:%23SVMa3Q3GHA.1464@TK2MSFTNGP03.phx.gbl...
> Oh, you made Form1 TopMost as well? I was only talking about a single
> "stay-on-top" form in an app. Any more than one is just asking for
> trouble, UI-wise, I think.

I have to agree with Chris, setting TopLevel to true on my machine doesn't
make any difference. If I set Form2 to toplevel I can still click Form1 and
it will come to the front.



Re: Form.TopMost behaviour by mabster

mabster
Wed Sep 20 18:58:23 CDT 2006

Michael C wrote:
> "mabster" <mabster@madprops.org> wrote in message
> news:%23SVMa3Q3GHA.1464@TK2MSFTNGP03.phx.gbl...
>> Oh, you made Form1 TopMost as well? I was only talking about a single
>> "stay-on-top" form in an app. Any more than one is just asking for
>> trouble, UI-wise, I think.
>
> I have to agree with Chris, setting TopLevel to true on my machine doesn't
> make any difference. If I set Form2 to toplevel I can still click Form1 and
> it will come to the front.

Weird. I'm sure it didn't behave like that in my test. I might have to
re-create it since I didn't bother saving it yesterday. :(