MouseDown/MouseUp 和点击事件不同步
MouseDown/MouseUp and Click events out of sync
我有一个 winforms 应用程序,可以捕获 MouseDown、MouseUp 和 Click 事件。
缓慢单击表单(大约一秒钟一次),事件计数器保持同步。
快速点击并且 down/up 事件计数保持跟踪,但点击事件计数落后:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private int clicks = 0;
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
clicks++;
textBox1.Text = clicks.ToString();
}
private int mdown=0;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mdown++;
textBox2.Text = mdown.ToString();
}
private int mup = 0;
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
mup++;
textBox3.Text = mup.ToString();
}
}
阅读文档:https://msdn.microsoft.com/en-us/library/ms171542.aspx这似乎不可能 - 我是否遗漏了一些明显的东西
(使用触控板按钮或外接蓝牙鼠标时会发生这种情况,希望这是编程错误而不是机器问题。)
编辑
Damien 当然是正确的,它也跟踪双击并且一切都保持同步:
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
clicks++;
textBox1.Text = clicks.ToString();
}
因为有时您的点击速度足够快以至于触发了双击。考虑您链接到的文档页面中的序列:
Following is the order of events raised for a double mouse-button click:
- MouseDown event.
- Click event.
- MouseClick event.
- MouseUp event.
- MouseDown event.
- DoubleClick event. (This can vary, depending on whether the control in question has the StandardDoubleClick style bit set to true. For more information about how to set a ControlStyles bit, see the SetStyle method.)
- MouseDoubleClick event.
- MouseUp event.
请注意,该序列中 MouseDown
/MouseUp
事件的数量是 MouseClick
事件的两倍。
我有一个 winforms 应用程序,可以捕获 MouseDown、MouseUp 和 Click 事件。
缓慢单击表单(大约一秒钟一次),事件计数器保持同步。
快速点击并且 down/up 事件计数保持跟踪,但点击事件计数落后:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private int clicks = 0;
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
clicks++;
textBox1.Text = clicks.ToString();
}
private int mdown=0;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mdown++;
textBox2.Text = mdown.ToString();
}
private int mup = 0;
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
mup++;
textBox3.Text = mup.ToString();
}
}
阅读文档:https://msdn.microsoft.com/en-us/library/ms171542.aspx这似乎不可能 - 我是否遗漏了一些明显的东西
(使用触控板按钮或外接蓝牙鼠标时会发生这种情况,希望这是编程错误而不是机器问题。)
编辑 Damien 当然是正确的,它也跟踪双击并且一切都保持同步:
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
clicks++;
textBox1.Text = clicks.ToString();
}
因为有时您的点击速度足够快以至于触发了双击。考虑您链接到的文档页面中的序列:
Following is the order of events raised for a double mouse-button click:
- MouseDown event.
- Click event.
- MouseClick event.
- MouseUp event.
- MouseDown event.
- DoubleClick event. (This can vary, depending on whether the control in question has the StandardDoubleClick style bit set to true. For more information about how to set a ControlStyles bit, see the SetStyle method.)
- MouseDoubleClick event.
- MouseUp event.
请注意,该序列中 MouseDown
/MouseUp
事件的数量是 MouseClick
事件的两倍。