手写代码实现窗体的拖动效果

代码
   
     
public partial class Form1 : Form
{
private Point oldPoint = new Point( 0 , 0 );
public Form1()
{
InitializeComponent();
}

private void linkLabel1_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e)
{
this .Close();
}

private void linkLabel2_MouseDown( object sender, MouseEventArgs e)
{
oldPoint.X
= Cursor.Position.X;
oldPoint.Y
= Cursor.Position.Y;
}

private void linkLabel2_MouseMove( object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int offset_x = Cursor.Position.X - oldPoint.X;
int offset_y = Cursor.Position.Y - oldPoint.Y;
this .Location = new Point( this .Location.X + offset_x, this .Location.Y + offset_y);
oldPoint.X
= Cursor.Position.X;
oldPoint.Y
= Cursor.Position.Y;
}
}
}

 

你可能感兴趣的:(代码)