Double click code never executes

O

objectref

Hi to all,

i have an app that i allow a drag and drop operation of picture boxes on a
panel.
when i drop a picture box i do the following so my newly dropped picture box
will be able
to respond to these 2 events:

pbox.MouseDown += new MouseEventHandler(pbox_MouseDown);
pbox.DoubleClick += new EventHandler(pbox_DoubleClick);

But although the code in MouseDown event executes correctly, the
pbox_DoubleClick
is never called...
It seems that because MouseDown is executing first, it cannot "understand"
the double click
and thus it;s code never executes...

Has anyone experienced this and come up to a solution ?

Below is the code for MouseDown event,

thanks a lot for any help!

private void pbox_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {
PictureBox pbox = (PictureBox) sender;
DragDropEffects myEffect;
FormInvoked = true;
switch (e.Button) {
case MouseButtons.Left: {
myEffect = pbox.DoDragDrop((Bitmap)
pbox.Image,DragDropEffects.Copy);
SetDefaultBox(pbox.Name);
break;
etc etc etc...
 
N

Nicholas Paldino [.NET/C# MVP]

objectref,

I think that this would be the case. Anytime you let up the mouse you
are starting a drag/drop operation which is going to cancel out the double
click timer (I think).

What you might have to do is on the mouse down, you would set a timer
(set to a little more than the double click timeout) and a flag indicating
that the mouse was down. Then, when the timer fires, if the double click
handler did not execute, then you would begin your drag/drop operation.

Hope this helps.
 

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