Just like QQ pet or Thunder hover window, mouse click down the form to follow the mouse move
The main is two time loading
MouseDown and MouseMove Events
MouseDown event:
1 private int _startx;//mouse point down the coordinates 2 private int _starty; 3 private void Form1_mousedown (object sender, MouseEventArgs e) 4 {5 _startx = e.x;//e is the mouse punctuation event 6 _starty = e.y;7 }
MouseMove Events
1 private void Form1_mousemove (object sender, MouseEventArgs e) 2 {3 if (E.button = = System.Windows.Forms.Mous Ebuttons.left) 4 {5 this . Left + = e.x-_startx;//minus the coordinates of the mouse point is the window that moves the position under the point 6 this . Top + = e.y-_starty;7 }8 }
If inside
E.button = = System.Windows.Forms.MouseButtons.Left Perform a move event when the left mouse button is down
If you do not add---the action of the form will be performed when the mouse moves over the form
How to make a mouse follow-up window--simple