tags:

views:

750

answers:

4
+2  Q: 

Form top most?

How can I display something over all other application. I want to to display something over all form of my program and all other programs open on my desktop (not mine).

*Top Most doesn't work I have tested and my browser can go OVER my application :S

Here is an image of when I use TopMost to TRUE. You can see my browser is over it...

http://www.freeimagehosting.net/uploads/5a98165605.png

+2  A: 

You can use the form instance and set the property TopMost to True.


If you want to be over all Windows, there are another way with Win32 Api calls.

Here is what you could do:

In your form class add :

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

In the form load you can add :

SetForegroundWindow(this.Handle);

This should do the trick.

Update

TopMost should do the job BUT: Top most OR/AND the Win32 Api call will only work not inside Visual Studio (well for Vista and with VS2008 I tested it... I can't tell for other). Try running the program with the .Exe from the /bin directory, it will works.

Daok
I just tested the TopMost property and it does set it above all windows.
Y Low
^^ aye, this is what I thought at well. What windows trump .TopMost?
Quibblesome
i edited be cause I read in MSDN that that should do that, but in practice I have a project that required more than only TopMost to be at the top. Maybe it was because the form hasn't any title.
Daok
I think SO should add a WORKS ON MY MACHINE feature.
Y Low
In my sample they work in VS2008 perfectly fine.
Y Low
It works outside VS2008 for me, but inside VS2008 it doesn't. Is it because I am on Vista??? (Thx Daok I might accept you if I have not a solution inside VS2008)
Pokus
I tried it on Server 2003.
Y Low
+4  A: 

The Form.TopMost property will set your form the top form above all other running windows applications (not just your forms.)

myForm.TopMost = true; // This will do the job
Y Low
+1  A: 

TopMost property is what you need (never had a problem with that)


On MSDN it says:

A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop.

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost.aspx

Bobby Z
See my link with a picture, why it doesn't work here?
Pokus
A: 

In my team we had a internal tool that keeps on running after Windows startup. It is a WinForm with TopMost set to ture. On Vista, sometimes we had the same problem. At very random times, the form will lost TopMost property and other non-topmost window can appear above it. I had a log of researches but found no answer and many other people had this same problem, it seems that on Vista at very low level there is a bug about TopMost property.