Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何计算鼠标在单击过程中移动的距离_C#_.net_Winforms_Mouseclick Event - Fatal编程技术网

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
并保留该点。然后在
鼠标单击事件中计算距离。