如何捕获 System.Windows.Forms.MonthCalendar 控件的双击事件?我尝试过使用 MouseDown 的 MouseEventArgs.Clicks 属性,但它始终为 1,即使我双击也是如此。
请注意,MonthCalendar 在“属性”窗口中既不显示 DoubleClick 也不显示 MouseDoubleClick 事件。麻烦的明显迹象是,本机 Windows 控件会阻止生成这些事件。您可以通过观察 MouseDown 事件并测量单击之间的时间来合成您自己的。
将新类添加到您的项目中并粘贴下面所示的代码。编译。从工具箱顶部放下新控件。为 DoubleClickEx 事件编写一个事件处理程序。
using System;
using System.Windows.Forms;
class MyCalendar : MonthCalendar {
public event EventHandler DoubleClickEx;
public MyCalender() {
lastClickTick = Environment.TickCount - SystemInformation.DoubleClickTime;
}
protected override void OnMouseDown(MouseEventArgs e) {
int tick = Environment.TickCount;
if (tick - lastClickTick <= SystemInformation.DoubleClickTime) {
EventHandler handler = DoubleClickEx;
if (handler != null) handler(this, EventArgs.Empty);
}
else {
base.OnMouseDown(e);
lastClickTick = tick;
}
}
private int lastClickTick;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)