zoukankan      html  css  js  c++  java
  • C#winform拖动无边框窗体

     private bool isMouseLeftKeyDown = false;
            private Point mousePointToClient = new Point();//相对于本窗体鼠标位置
            private Point mousePointToScreen = new Point();//相对于屏幕鼠标位置
    
            private void Form_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
    Control ctrl = sender as Control; isMouseLeftKeyDown = true; this.mousePointToClient = new Point(e.X + ctrl.Location.X, e.Y + ctrl.Location.Y); this.mousePointToScreen = Control.MousePosition; } } private void Form_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && isMouseLeftKeyDown) { this.Top = Control.MousePosition.Y - mousePointToClient.Y; this.Left = Control.MousePosition.X - mousePointToClient.X; } } private void Form_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseLeftKeyDown = false; FormClick(); } } private void FormClick() { //鼠标位置没有发成偏移,视为点击事件 if (mousePointToScreen != Control.MousePosition) return; //todo }

      

  • 相关阅读:
    405
    406
    4-1
    3-11
    3-10
    3-9
    3-8
    3-7
    3-5
    3-4
  • 原文地址:https://www.cnblogs.com/yaosj/p/10677075.html
Copyright © 2011-2022 走看看