Hi J,
The reason why the Click event is always raised before the DoubleClick
event of a control when the user double clicks on the control is that the
system always sends a WM_LBUTTONDOWN message to the control before sends a
WM_LBUTTONDBLCLK message.
Once the control receives the WM_LBUTTONDOWN message, the Click event of
the control is raised.
If you don't like to get the Click event fired before the DoubleClick event
is raised, I think a possible way is to hold the WM_LBUTTONDOWN message for
a short time when the control receives the this message. If the control
doesn't receive the WM_LBUTTONDBLCLK message during this short time, then
send this message out; otherwise, don't send.
The following is a sample.
using System.Runtime.InteropServices;
class MyControl : Control
{
int WM_LBUTTONDOWN = 0x0201;
int WM_LBUTTONDBLCLK = 0x0203;
Message clickMessage;
System.Windows.Forms.Timer clickTimer = new
System.Windows.Forms.Timer();
bool clickflag = false;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,int msg, IntPtr
wParam, IntPtr lParam);
public MyControl()
{
clickTimer.Interval = 100;
clickTimer.Tick += new EventHandler(clickTimer_Tick);
}
void clickTimer_Tick(object sender, EventArgs e)
{
this.clickTimer.Stop();
clickflag = true;
SendMessage(this.Handle, clickMessage.Msg, clickMessage.WParam,
clickMessage.LParam);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONDOWN)
{
if (clickflag == false)
{
clickMessage = m;
clickTimer.Start();
}
else
{
clickflag = false;
base.WndProc(ref m);
}
}
else if (m.Msg == WM_LBUTTONDBLCLK)
{
clickTimer.Stop();
base.WndProc(ref m);
}
else
{
base.WndProc(ref m);
}
}
}
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.