Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MouseDown and Click conflict

I have a Drag() method on form_MouseDown event. I also have a click event on the form. The problem is that if I click on the form, MouseDown event gets triggered and it never gets the chance to trigger click event.

What is the best way to solve this issue? I was thinking counting pixels if the form is actually dragged, but there has to be a better way. Any suggestions?

like image 709
Kristian Avatar asked Mar 10 '13 12:03

Kristian


People also ask

Is Mousedown the same as click?

Note: This differs from the click event in that click is fired after a full click action occurs; that is, the mouse button is pressed and released while the pointer remains inside the same element. mousedown is fired the moment the button is initially pressed.

Does touch trigger Mousedown?

Because mobile browsers should also work with with web applications that were build for mouse devices, touch devices also fire classic mouse events like mousedown or click . When a user follows a link on a touch device, the following events will be fired in sequence: touchstart. touchend.

What is mouseup and Mousedown events?

Occur when the user clicks a mouse button. MouseDown occurs when the user presses the mouse button; MouseUp occurs when the user releases the mouse button.

Does mouseup fire before click?

Mouseup is always firing before click, despite this order.


1 Answers

I found this solution, although it is for a double-click and a mouse down events:

void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && e.Clicks ==1)
{
PictureBox pb = (PictureBox)sender;
DoDragDrop((ImageData)pb.Tag, DragDropEffects.Copy);
}
}

source: http://code.rawlinson.us/2007/04/c-dragdrop-and-doubleclick.html

like image 197
Nico Mondragon Diego Avatar answered Oct 01 '22 13:10

Nico Mondragon Diego