MonthCalendar (Calendar control) extends DoubleClick events
A blog from the Seaway
C # Beginners is not very difficult, learning C, learning Java can be easy to get started, but only the introduction. The real battle is the actual problem encountered in the development process, yesterday in the development of a Calendar control (MonthCalendar) associated with the project, would like to use the DoubleClick event to close the control and then pass the value, it is so simple. But found that Microsoft since did not provide MonthCalendar in the DoubleClick incident, why not know why, but the problem must be solved, there is no way, can only expand their own hands.
Here's how to share the solution. Some of the code referring to foreign networks.
First you need to create a new custom control inheritance MonthCalendar
Several important methods, such as onmousedown and OnDoubleClick, can be rewritten
Code Area
public partial class Cldar:monthcalendar
{
Private point m_lastclickposition;
Private long m_lastclicktime;
Private Boolean M_lastclickraiseddoubleclick;
Public Cldar ()
{
InitializeComponent ();
}
protected override void OnPaint (PaintEventArgs pe)
{
Todo:add Custom Paint code here
Calling the base class OnPaint
Base. OnPaint (PE);
}
/**////<summary>
Modechanged Event.
</summary>
[Browsable (True)]
[Category ("Basic_event"), Description ("The event of a MonthCalendar attack.")]
public event EventHandler DoubleClick;
protected override void OnDoubleClick (EventArgs e)
{
DoubleClick (this, e);
Base. OnDoubleClick (e);
}
BOOL Isindoubleclickarea (Point Point1, point Point2)
{
Return Math.Abs (point1.x-point2.x) <= SystemInformation.DoubleClickSize.Width &&
Math.Abs (POINT1.Y-POINT2.Y) <= SystemInformation.DoubleClickSize.Height;
}
protected override void OnMouseDown (MouseEventArgs e)
{
if (E.button = = MouseButtons.Left)
{
if (!m_lastclickraiseddoubleclick && system.datetime.now.ticks-m_lastclicktime <= Systeminformation.doubleclicktime * 10000 && Isindoubleclickarea (m_lastclickposition, Cursor.Position))
{
OnDoubleClick (Eventargs.empty);
M_lastclickraiseddoubleclick = true;
}
Else
{
M_lastclickraiseddoubleclick = false;
}
M_lastclickposition = cursor.position;
M_lastclicktime = System.DateTime.Now.Ticks;
}
Base. OnMouseDown (e);
}
}