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 @   Kyle0418  阅读(696)  评论(3编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示