如何计算鼠标点击时移动的距离
How to calculate the distance that the mouse moved during click
我有这个代码:
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
并保持这一点。然后在MouseClick
事件中计算距离:
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}");
}
我有这个代码:
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
并保持这一点。然后在MouseClick
事件中计算距离:
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}");
}