Public partial class Form1: Form {
// Record the X coordinate of the form
Private int startX;
// Record the Y coordinate of the form
Private int startY;
Public Form1 (){
InitializeComponent ();
}
/// <Summary>
/// Left click
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void button#mousedown (object sender, MouseEventArgs e ){
// Determine if the clicked button is left
If (e. Button = MouseButtons. Left ){
// Obtain the X value of the form.
StartX = e. X;
// Obtain the Y value of the form.
StartY = e. Y;
}
}
/// <Summary>
/// Move the mouse
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void button=mousemove (object sender, MouseEventArgs e ){
// Determine if the clicked button is left
If (e. Button = MouseButtons. Left ){
// Redraw form X
This. Left + = e. X-startX;
// Redraw form Y
This. Top + = e. Y-startY;
}
}
}
From: happy pig's column