其他分享
首页 > 其他分享> > 拖动winform无边框

拖动winform无边框

作者:互联网

当winForm窗体FormBorderStyle属性改为None时,winForm窗体就会变成无边框。但此时会出现鼠标无法拖动winForm窗体现象,这个时候添加以下代码和事件就能恢复正常,具体代码如下:


        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        private const int VM_NCLBUTTONDOWN = 0XA1;
        private const int HTCAPTION = 2;

     private void Form_MouseDown(object sender, MouseEventArgs e)  //窗体事件(鼠标按下按钮时发生)
     {
      ReleaseCapture();
      SendMessage((IntPtr)this.Handle, VM_NCLBUTTONDOWN, HTCAPTION, 0);
      }

标签:拖动,DllImport,private,边框,int,窗体,extern,winForm,winform
来源: https://www.cnblogs.com/TanOnly/p/15707731.html