Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

c# - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...