MonthCalendar (Calendar control) extends DoubleClick events

Source: Internet
Author: User
Tags abs datetime

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.