当取消操作时,DragLeave会触发,如何验证?

时间:2013-09-25 11:16:22

标签: c# .net winforms drag-and-drop

有没有人知道我如何验证是否因为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);
    }
  }
}

0 个答案:

没有答案