Topmost property

S

Simanovsky

Hello,

I've got a problem with making a form topmost in the
application.
I need that a form is shown on top of other forms of my
application, but it should not be on top of other
applications windows.
I tried to use Form.TopMost property, but if I use it
the form appears also on top of other applications even
when the focus is not in my application. Callling
Form.BringToFront() on Focus event also does not work.
Has anybody any ideas on how I can achieve the desired
form behaviour?

Thanks in advance,
A.Simanovsky
 
R

Robert Jacobson

There's an API call that might help, SetWindowLong with the GWL_HWNDPARENT
flag set. It takes the handles to two forms as an input, and makes one the
parent of the other -- the parent being below, and the child being always
on top of the parent.

There's some sample code in this post:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OD9lA6HtCHA.1644@TK2MSFTNGP12

And more discussion of it here:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=eJ9l9g2JCHA.2160@tkmsftngp10
(Complete thread)

You can also try the SetParent api call, but this is makes one form a child
MDI form to a parent form -- it doesn't just make it on top.

Hope this helps,
Robert Jacobson
 
T

Tom

I found the easiest thing to do is something like:
dlgField.Owner = this.ParentForm;
(if your poping it up from a control), or

dlgField.Owner = this;

if you're bringing it up from a Form.

Tom Clement
Apptero, Inc.
 
R

Robert Jacobson

I think that will make it behave like an MDI child window -- the child won't
be able to be positioned outside of the main form. (It gives the same
result as the SetParent api call, as far as I know.) That can be good or
bad, depending on what you need.
 
T

Tom

It actually does just what the original poster wants, as far as I can tell.
It doesn't limit the child to the boundaries of the parent form.
Tom
 
S

Simanovsky

Hello Robert, Tom,

Thanks a lot. Your advice with SetWindowLong did help.
I also used Form.ShowDialog(IWin32Window) for modal forms.
Unfortunately, I could not use Form.Owner property as Tom
have suggested -- I'm sorry for not stating that my main
application window is not a .NET form.

WBR,
A.Simanovsky
 

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