C#调用API 实现窗体总在最上

class Win32
        {
            [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
            public static extern bool SetWindowPos(
                int hWnd,               // window handle     
                int hWndInsertAfter,    // placement-order handle     
                int X,                  // horizontal position     
                int Y,                  // vertical position     
                int cx,                 // width     
                int cy,                 // height     
                uint uFlags);           // window positioning flags  
            public const int HWND_BOTTOM = 0x1;
            public const uint SWP_NOSIZE = 0x1;
            public const uint SWP_NOMOVE = 0x2;
            public const uint SWP_SHOWWINDOW = 0x40;
        }

        private void ShoveToBackground()
        {
            Win32.SetWindowPos((int)this.Handle, -1, this.Location.X, this.Location.Y, this.Size.Width, this.Size.Height, 1);

            //Win32.SetWindowPos(
            //    (int)this.Handle,
            //    (int),
            //    0, 0, 0, 0,
            //    Win32.SWP_NOMOVE | Win32.SWP_NOSIZE | Win32.HWND_BOTTOM);
        }

        private void Bar_Activated(object sender, EventArgs e)
        {
            //总在最上
            ShoveToBackground();
        }
        private void Bar_Leave(object sender, EventArgs e)
        {
            //总在最上
            ShoveToBackground();
        }

原文地址:https://www.cnblogs.com/yinhaosln/p/1504482.html