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_LBUTTONDBLCL K 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_LBUTTONDBLCL K 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_LBUTTONDBLCL K = 0x0203;
Message clickMessage;
System.Windows. Forms.Timer clickTimer = new
System.Windows. Forms.Timer();
bool clickflag = false;
[DllImport("user 32.dll")]
public static extern int SendMessage(Int Ptr hWnd,int msg, IntPtr
wParam, IntPtr lParam);
public MyControl()
{
clickTimer.Inte rval = 100;
clickTimer.Tick += new EventHandler(cl ickTimer_Tick);
}
void clickTimer_Tick (object sender, EventArgs e)
{
this.clickTimer .Stop();
clickflag = true;
SendMessage(thi s.Handle, clickMessage.Ms g, clickMessage.WP aram,
clickMessage.LP aram);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONDOWN)
{
if (clickflag == false)
{
clickMessage = m;
clickTimer.Star t();
}
else
{
clickflag = false;
base.WndProc(re f m);
}
}
else if (m.Msg == WM_LBUTTONDBLCL K)
{
clickTimer.Stop ();
base.WndProc(re f m);
}
else
{
base.WndProc(re f 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/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.