djd*_*d87 11
您需要使用MouseDown
和MouseUp
事件记录鼠标何时向下和向上:
private bool mouseIsDown = false;
private Point firstPoint;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
firstPoint = e.Location;
mouseIsDown = true;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
mouseIsDown = false;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,第一点正在被记录,因此您可以MouseMove
按如下方式使用该事件:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseIsDown)
{
// Get the difference between the two points
int xDiff = firstPoint.X - e.Location.X;
int yDiff = firstPoint.Y - e.Location.Y;
// Set the new point
int x = this.Location.X - xDiff;
int y = this.Location.Y - yDiff;
this.Location = new Point(x, y);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10679 次 |
最近记录: |