有没有人知道我如何验证是否因为DragAction更改为取消而引发了事件,还是因为它实际上是从控件中拖出了对象?
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dragleave.aspx
[编辑]
在这部分中,我开始拖动被拖动的对象。
void control_MouseDown(object sender, MouseEventArgs e)
{
var wasClicked = WasClicked;
if (wasClicked != null)
{
WasClicked(this, EventArgs.Empty);
}
// Select this UC on click.
if (IsSelected == false)
IsSelected = true;
else
IsSelected = false;
if (IsSelected == true)
{
_beingDragged = true;
DoDragDrop(this, DragDropEffects.Move);
}
return;
}
此部分事件在被拖动的对象离开FlowLayoutPanel时验证。
private void LocationControl_DragLeave(object sender, EventArgs e)
{
foreach (Control c in Controls)
{
if (((PersonDragDrop)c).beingDragged == true)
{
((PersonDragDrop)c).LeaveLocation();
DeletePerson((PersonDragDrop)c);
}
}
}