C# SetWindowPos窗口置頂使用說明
更新時間:2012年12月20日 11:46:52 作者:
就是有時候窗口不能夠成功置頂,這時需要重新切換下標(biāo)簽,就可以置頂了,本文介紹C# SetWindowPos實現(xiàn)窗口置頂?shù)姆椒?/div>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
/// <summary>
/// 得到當(dāng)前活動的窗口
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetForegroundWindow();
哪個窗體想要置頂,在Form_Load中加上
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后參數(shù)也有用1 | 4
具體說明,看API函數(shù)說明
如果是用點擊一個按鈕后彈出新窗體,并置頂,則:
Form2 frm = new Form2();
frm.Show();
SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
這樣,新打開的窗體就是置頂了
復(fù)制代碼 代碼如下:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
/// <summary>
/// 得到當(dāng)前活動的窗口
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetForegroundWindow();
哪個窗體想要置頂,在Form_Load中加上
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后參數(shù)也有用1 | 4
具體說明,看API函數(shù)說明
如果是用點擊一個按鈕后彈出新窗體,并置頂,則:
復(fù)制代碼 代碼如下:
Form2 frm = new Form2();
frm.Show();
SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
這樣,新打開的窗體就是置頂了
您可能感興趣的文章:
相關(guān)文章
ASP.NET Core利用Jaeger實現(xiàn)分布式追蹤詳解
這篇文章主要給大家介紹了關(guān)于ASP.NET Core利用Jaeger實現(xiàn)分布式追蹤的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用ASP.NET Core具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04.NetCore?Web?Api?利用ActionFilterAttribute統(tǒng)一接口返回值格式及問題解析
在實際項目開發(fā)過程中,統(tǒng)一API返回值格式對前端或第三方調(diào)用將是非常必要的,在.NetCore中我們可以通過ActionFilterAttribute來進(jìn)行統(tǒng)一返回值的封裝,對.NetCore?Web?Api?統(tǒng)一接口返回值格式相關(guān)知識感興趣的朋友一起看看吧2022-03-03先裝了FRAMEWORK,后裝IIS導(dǎo)致asp.net頁面無法訪問的解決方法
如果先裝了FRAMEWORK,后裝IIS。有可能沒有在IIS中注冊,就會導(dǎo)致在頁面中無法訪問的情況2012-01-01