click and doubleclick

M

magic gooddy

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.
 
M

magic gooddy

I said I take code from article

// Derive a button with extended funtionality
// from the Button class.
using System;
using System.Windows.Forms;

public 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 = SystemInformation.DoubleClickTime;

public new event EventHandler DoubleClick;

protected override void OnClick(EventArgs e)
{
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);
}

// 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);
}
}
*********************
// Create an instance of the DoubleClickButton class.
DoubleClickButton dClickB = new DoubleClickButton();

dClickB.Bounds = new Rectangle(20, 10, 200, 30);
dClickB.Text = "Click me twice!";
Controls.Add(dClickB);



// Add the DClick event hander to the DoubleClick event.
dClickB.DoubleClick += new EventHandler(DClick);

dClickB.Click += new EventHandler(dClickB_Click);

}

void dClickB_Click(object sender, EventArgs e)
{
MessageBox.Show("One click");
}

private void DClick(object o, EventArgs e)
{
MessageBox.Show("Nice job!");
}
 
P

Paul G. Tobey [eMVP]

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.
 
M

magic gooddy

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> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
 
P

Paul G. Tobey [eMVP]

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.
 
P

Paul G. Tobey [eMVP]

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.
 
M

magic gooddy

I'm sorry, but your code don't work
I paste your code instead my code and run sample. I see Click only.

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
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.
 
C

Christian Resma Helle

Hey you guys are right! I thought that since Control has a DoubleClick event
then all the inheriting controls would support it and also coz the Button
control actually receives a WM_LBUTTONDBLCLK event when you double click it.

--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top