【发布时间】:2011-09-27 09:58:42
【问题描述】:
我想禁用一个按钮-以防止双击:在平板电脑上,您按下一次,它单击了两次,这是我所知道的最简单的 hack-,但我注意到了/debugged 间隔在实践中可能太长了; 50 毫秒 vs > 2 秒。
只有一行启动计时器,一行停止。随机间隔为 50 毫秒或更大。没有 CPU 消耗,我只需在我的 4 核台式电脑上用鼠标单击按钮。
是什么原因?
DispatcherTimer timerTouchDelay = new DispatcherTimer();
protected override void OnMouseDown(MouseButtonEventArgs e)
{
//Init
if (timerTouchDelay.Interval.Milliseconds == 0)
{
timerTouchDelay.Tick += new EventHandler(timerTouchDelay_Tick);
timerTouchDelay.Interval = new TimeSpan(0, 0, 0, 0, 50); //ms
}
if(timerTouchDelay.IsEnabled)
return;
timerTouchDelay.Start();
HandleKeyDown();
base.OnMouseDown(e);
}
private void timerTouchDelay_Tick(object sender, EventArgs e)
{
timerTouchDelay.Stop();
}
【问题讨论】:
-
你不能只在 OnMouseDown 函数中禁用它并在第一个 timerTouchDelay_Tick 上启用它。
标签: c#