开发者

How to make a window topmost only one time

I want to make a window topmost in a C# application. i need to make it so that while the window is loaded(the application is invoked by a third party software) it will be on top and u开发者_StackOverflow中文版ser can browse to other windows if he needed.

I used

this.Topmost = true; 
this.TopMost=false; 

but it dont have any effect.


TopMost only applies to forms within your application. If you want to bring your form to the top of other applications running on your computer, I suggest you take a look at this question:

Bringing window to the front in c# using win 32 api


I can suggest you to use native API. SetWindowPos function from user32.dll

something like this, but it should be converted to C# code, i think it wouldn't be difficult. HWND_TOPMOST flag is just what you needed

 RECT rect;
// get the current window size and position
GetWindowRect(hWnd, &rect );
// now change the size, position, and Z order
// of the window.
SetWindowPos(hWnd ,       // handle to window
HWND_TOPMOST,  // placement-order handle
rect.left,     // horizontal position
rect.top,      // vertical position
rect.right,  // width
rect.bottom, // height
SWP_SHOWWINDOW );// window-positioning options


UPDATE
READ THIS http://social.msdn.microsoft.com/forums/en-US/winforms/thread/bf3117f8-d83d-4b00-8e4f-7398b559a2dd/

If the forms are in different applications, you can get the window you want to bring to front by calling the FindWindow API, and SetForegroundWindow API to bring it to front, for more information, you can read these likes

FindWindow http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx

SetForegroundWindow http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx


this.Activate() 

should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜