C# winform 無邊框窗口 移動

給本身留個筆記, 在用wke作界面的時候. 每每須要把winform窗口設置成無邊框this

可是WebUI也須要移動窗口, 因此才把之前在易語言中用的方法翻譯過來使用spa

第零步: 設置無邊框窗口翻譯

form屬性設置 FormBorderStyle = None

第一步: 引用code

using System.Runtime.InteropServices;

第二步: 聲明DLL調用方法orm

//窗口是否最大化, 最大化返回true 不然false
[DllImport("user32.dll")]
public static extern bool IsZoomed(IntPtr hwnd);
//釋放捕獲
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
//發送消息
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

第三步: 爲」鼠標按下(MouseDown)」事件添加功能代碼blog

private void Login_MouseDown(object sender, MouseEventArgs e)
{
    //鼠標左鍵按下
    if (e.Button == MouseButtons.Left)
    {
        if (IsZoomed(this.Handle) == false)
            {
                ReleaseCapture(); 
                SendMessage(this.Handle, 161, 2, 0); 
            }
    }  
}

這裏寫圖片描述
這樣功能就實現辣事件

相關文章
相關標籤/搜索