2011-02-15 58 views
0

我想在C#應用程序中創建一個最頂層的窗口。我需要做到這一點,以便在窗口加載時(應用程序由第三方軟件調用),它將位於頂部,如果需要,用戶可以瀏覽到其他窗口。如何使窗口最頂層只有一次

我用

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

,但它不具有任何影響。

+0

如果您的應用運行兩次會發生什麼?我喜歡用高興的盔甲來決定死亡的窗戶形式。 – asawyer 2011-02-15 21:25:33

回答

0

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

如果形式在不同的應用程序,你可以通過調用FindWindow函數API得到你想要把到前窗,以及SetForegroundWindow API來把它前面,瞭解更多信息,可以閱讀這些喜歡

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

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

0

我可以建議你使用本機API。 SetWindowPos函數來自user32.dll

這樣的事情,但它應該轉換爲C#代碼,我認爲這不會有困難。 HWND_TOPMOST標誌是你需要的正是

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 
0
this.Activate() 

應該做的伎倆。