How do I capture a doubleclick event of the System.Windows.Forms.MonthCalendar control? I've tried using MouseDown's MouseEventArgs.Clicks property, but it is always 1, even if I doubleclick.
Do note that MonthCalendar neither shows the DoubleClick nor the MouseDoubleClick event in the Property window. Sure sign of trouble, the native Windows control prevents those events from getting generated. You can synthesize your own by watching the MouseDown events and measuring the time between clicks.
Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox. Write an event handler for the DoubleClickEx event.
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;
}