I just wrote my own DoubleClickButton with the primary change being that it
doesn't send Click on the second click of a double-click and it works fine
with catching both the click and the double-click. I'm fairly confident
that you're doing something flakey. My version is below:
-----
class DoubleClickButton : System.Windows.Forms.Button
{
// Note that the DoubleClickTime property gets
// the maximum number of milliseconds allowed between
// mouse clicks for a double-click to be valid.
int previousClick = 0; // ???? huh? SystemInformation.DoubleClickTime;
public new event EventHandler DoubleClick;
protected override void OnClick(EventArgs e)
{
// This is really dumb. We want the event time, not the current
// time!
int now = System.Environment.TickCount;
// A double-click is detected if the the time elapsed
// since the last click is within DoubleClickTime.
if (now - previousClick <= SystemInformation.DoubleClickTime)
{
// Raise the DoubleClick event.
if (DoubleClick != null)
DoubleClick(this, EventArgs.Empty);
previousClick = 0;
}
else
{
// Set previousClick to now so that
// subsequent double-clicks can be detected.
previousClick = now;
// Allow the base class to raise the regular Click event.
base.OnClick(e);
}
}
// Event handling code for the DoubleClick event.
protected new virtual void OnDoubleClick(EventArgs e)
{
if (this.DoubleClick != null)
this.DoubleClick(this, e);
}
}
-----
Paul T.
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:
[email protected]...
How long does it take for your Click handler to run? Remember that any
time spent in your handler counts against the time-out for double-click,
so, if you're doing some serious processing, it's quite possible that,
although you're waiting for double-click and although the right code
would run, you've set up your code so that it delays processing of the
next click long enough to prevent double-click from ever being detected.
I don't like how they calculated the time for when the events happened,
but that may just be the best that can be done with .NET CF. It would be
better to take the event time from the WM_LBUTTONDOWN message, if it's
sent as part of the EventArgs and compare that with the next click event
time to decide if it's a double-click or not...
Paul T.
magic gooddy said:
Yes, I need Click and DoubleClick. Is it impossible?
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
I don't see any sign that there's a DoubleClick event in 2.0 (VS2008
doesn't, either). .NET CF 3.5 doesn't have the DoubleClick event,
either.
For the original poster, are you saying that, in addition to
subclassing Button and creating your own DoubleClickButton class that
handles doing the double-click that you are *also*, in a class that
uses the DoubleClickButton, trying to capture the Click event?
Paul T.
Are you sure?
I see MSDN, do not supports
"Christian Resma Helle" <
[email protected]> ???????/???????? ?
???????? ?????????:
I think Button.DoubleClick is included in the .NETCF 2.0.
--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com
"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
I don't see any code in your example to subscribe to a DoubleClick.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
I build a sample from article How to: Create a Custom Double-Click
Event (
http://msdn.microsoft.com/en-us/library/ms172533.aspx). I add
my code:
dClickB.Click += new EventHandler(dClickB_Click);
void dClickB_Click(object sender, EventArgs e)
{
MessageBox.Show("Simple Click");
}
But DoubleClick event don't work now. I see simple Click only. Why?
I need Click and DoubleClick events for button.