问题
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!
回答1:
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
回答2:
I found this solution on this link
private void MyMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
Control source = (Control)sender;
source.DoDragDrop(new MyWrapper(source), DragDropEffects.Move);
}
}
by Bill Rawlinson — 18 Apr 2007
来源:https://stackoverflow.com/questions/32384222/c-sharp-distinguish-drag-drop-and-mouse-click