gpt4 book ai didi

c# - MouseDown/MouseUp 和 Click 事件不同步

转载 作者:行者123 更新时间:2023-11-30 20:37:46 32 4
gpt4 key购买 nike

我有一个 winforms 应用程序,可以捕获 MouseDown、MouseUp 和 Click 事件。

缓慢点击表单(大约一秒钟一次),事件计数器保持同步。

快速点击,向下/向上事件计数保持跟踪,但点击事件计数落后:

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();
}
}

enter image description here

阅读文档: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:

  1. MouseDown event.
  2. Click event.
  3. MouseClick event.
  4. MouseUp event.
  5. MouseDown event.
  6. 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.)
  7. MouseDoubleClick event.
  8. MouseUp event.

请注意,在该序列中 MouseDown/MouseUp 事件的数量是 MouseClick 事件的两倍。

关于c# - MouseDown/MouseUp 和 Click 事件不同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35751567/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com