winform 点击控件拖动窗体

Posted on 2017-05-11 15:11 熊阳123 阅读(...) 评论(...) 编辑 收藏
       private Point mPoint = new Point();
 
         private void 选择控件_MouseDown(object sender, MouseEventArgs e)
         {
             mPoint.X = e.X;
             mPoint.Y = e.Y;
         }
 
         private void 选择控件_MouseMove(object sender, MouseEventArgs e)
         {
             if (e.Button == MouseButtons.Left)
             {
                 Point myPosittion = MousePosition;
                 myPosittion.Offset(-mPoint.X, -mPoint.Y);
                 Location = myPosittion;
             } 
         }