WinFrom窗体始终置顶

调用WindowsAPI使窗体始终保持置顶效果,不被其他窗体遮盖:

        [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();

使用方式:在需要置顶的窗体的Load方法里面加上

//Load
private void Form1_Load(object sender, EventArgs e)
{
    try
    {
        SetWindowPos(, , , , ,  | );
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    //3764
}  
上一篇:简单的一句sql


下一篇:【Netbeans】表格的使用