简体   繁体   中英

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

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.

Form.TopMost属性将您的表单设置为所有其他正在运行的Windows应用程序(不仅仅是您的表单)上方的顶部表单。

myForm.TopMost = true; // This will do the job

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM