Winform无边框拖动

设置无边框 Form:

public Customize()
{
    InitializeComponent();
    this.FormBorderStyle = FormBorderStyle.None;
}

通过重写 WndProc 实现无边框窗体的拖动:

private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
// Implement the drag of the form
protected override void WndProc(ref Message message)
{
    base.WndProc(ref message);

    if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
    {
        message.Result = (IntPtr)HTCAPTION;
    }
}
posted @ 2019-01-21 16:19  Kyle0418  阅读(688)  评论(3编辑  收藏  举报