Search code examples
c#eventstriggerscursor

C# distinguish Drag drop and Mouse click


I have a form which allows drop and also I need to capture the click event.

The tricky part here, is when the user drags and drop the object on the form, the MouseClickEvent also fired-because he also clicked the mouse to release the drop.

How may I handle each on of this events in a separate event trigger?

Thanks in advance!

This is a short and more logic question so i didn't see a real reason to put pieces of code here..

Thanks!


Solution

  • Add a global boolean, for instance:

    private bool isDragAndDrop;
    

    Set it to false when loading the form. When the dragAndDrop event is fired you should set isDragAndDrop = true.

    When the Click event is fired you check if(!isDragAndDrop) This will or will not execute the code inside the click event based on the value on the isDragAndDrop -variable.

    Before leaving the click event you the set isDragAndDrop = false