C# 如何计算鼠标在单击过程中移动的距离
我有以下代码:C# 如何计算鼠标在单击过程中移动的距离,c#,.net,winforms,mouseclick-event,C#,.net,Winforms,Mouseclick Event,我有以下代码: private void Form1_MouseClick(object sender, MouseEventArgs e) { if(chckeckbox.checked) { //the distance that the mouse made when the left click remained clicked } } 我必须通过什么来更改注释,使其生效? 除此之外,如果它已经在某个事件中找到了,那么我有点迷路了。。。我必须把它放
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if(chckeckbox.checked)
{
//the distance that the mouse made when the left click remained clicked
}
}
我必须通过什么来更改注释,使其生效?
除此之外,如果它已经在某个事件中找到了,那么我有点迷路了。。。我必须把它放在另一个事件中,或者它在这里很好
PS:我曾经尝试过类似的东西,但它总是给我0分
Form1 testa = new Form1();
Point i = testa.Location;
Point z = testa.Location;
int res = i.X - z.X;
int pls = i.Y - z.Y;
按住鼠标向下移动
MouseDown
并保留该点。然后在鼠标单击事件中计算距离:
Point p1;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
p1 = e.Location;
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
MessageBox.Show($"dx = {e.Location.X - p1.X}, dy= {e.Location.Y - p1.Y}");
}
按住鼠标向下移动MouseDown
并保留该点。然后在鼠标单击事件中计算距离。