程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> C#SetWindowPos窗口置頂

C#SetWindowPos窗口置頂

編輯:關於ASP.NET

     [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>
    /// 得到當前活動的窗口
    /// </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); //最後參數也有用1 | 4 
    具體說明,看API函數說明
    如果是用點擊一個按鈕後彈出新窗體,並置頂,則:

    Form2 frm = new Form2();
    frm.Show();
    SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved