Control.DragLeave Control.DragLeave Control.DragLeave Control.DragLeave Event

定义

将对象拖出控件的边界时发生。Occurs when an object is dragged out of the control's bounds.

public:
 event EventHandler ^ DragLeave;
public event EventHandler DragLeave;
member this.DragLeave : EventHandler 
Public Custom Event DragLeave As EventHandler 

示例

下面的代码示例演示了两个之间拖放操作ListBox控件。The following code example demonstrates a drag-and-drop operation between two ListBox controls. 此示例调用DoDragDrop当拖动操作开始时的方法。The example calls the DoDragDrop method when the drag action starts. 如果已移动鼠标拖动操作启动多个SystemInformation.DragSize鼠标位置在从MouseDown事件。The drag action starts if the mouse has moved more than SystemInformation.DragSize from the mouse location during the MouseDown event. IndexFromPoint方法用于确定要在拖动的项的索引MouseDown事件。The IndexFromPoint method is used to determine the index of the item to drag during the MouseDown event.

示例还演示如何使用自定义光标拖放操作。The example also demonstrates using custom cursors for the drag-and-drop operation. 该示例需要两个光标文件3dwarro.cur3dwno.cur、 存在于应用程序目录,用于自定义拖动和不可拖动光标,分别。The example requires that two cursor files, 3dwarro.cur and 3dwno.cur, exist in the application directory, for the custom drag and no-drop cursors, respectively. 如果将使用自定义光标UseCustomCursorsCheckCheckBox检查。The custom cursors will be used if the UseCustomCursorsCheckCheckBox is checked. 在中设置自定义光标GiveFeedback事件处理程序。The custom cursors are set in the GiveFeedback event handler.

键盘状态进行评估DragOver事件处理程序的权利ListBox,以确定拖动操作将为基于 SHIFT、 CTRL、 ALT 或 CTRL + ALT 键的状态。The keyboard state is evaluated in the DragOver event handler for the right ListBox, to determine what the drag operation will be based on state of the SHIFT, CTRL, ALT, or CTRL+ALT keys. 中的位置ListBox期间还确定发生下拉DragOver事件。The location in the ListBox where the drop would occur is also determined during the DragOver event. 如果要删除的数据不是String,则DragEventArgs.Effect设置为NoneDragDropEffectsIf the data to drop is not a String, then the DragEventArgs.Effect is set to None in DragDropEffects. 最后,在显示状态的下拉DropLocationLabel LabelFinally, the status of the drop is displayed in the DropLocationLabelLabel.

若要删除的权利的数据ListBox在中确定DragDrop事件处理程序和String值中的适当位置添加ListBoxThe data to drop for the right ListBox is determined in the DragDrop event handler and the String value is added at the appropriate place in the ListBox. 如果拖动操作移动边界以外的窗体,则在取消拖放操作QueryContinueDrag事件处理程序。If the drag operation moves outside the bounds of the form, then the drag-and-drop operation is canceled in the QueryContinueDrag event handler.

这段代码摘录演示了如何使用DragLeave事件。This code excerpt demonstrates using the DragLeave event. 请参阅DoDragDrop完整的代码示例的方法。See the DoDragDrop method for the complete code example.

void ListDragTarget_DragLeave( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
  // Reset the label text.
   DropLocationLabel->Text = "None";
}
private void ListDragTarget_DragLeave(object sender, System.EventArgs e) {
    // Reset the label text.
    DropLocationLabel.Text = "None";
}
Private Sub ListDragTarget_DragLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListDragTarget.DragLeave

    ' Reset the label text.
    DropLocationLabel.Text = "None"
End Sub

注解

DragLeave用户拖动控件超出游标或用户取消当前的拖放操作时引发事件。The DragLeave event is raised when the user drags the cursor out of the control or the user cancels the current drag-and-drop operation.

下面描述与拖放操作相关的事件的引发方式以及引发时间。The following describes how and when events related to drag-and-drop operations are raised.

DoDragDrop方法确定当前游标位置下的控件。The DoDragDrop method determines the control under the current cursor location. 然后检查以查看该控件是否有效的放置目标。It then checks to see if the control is a valid drop target.

如果控件是有效的放置目标,GiveFeedback指定的拖放效果引发事件。If the control is a valid drop target, the GiveFeedback event is raised with the drag-and-drop effect specified. 有关拖放效果的列表,请参见 DragDropEffects 枚举。For a list of drag-and-drop effects, see the DragDropEffects enumeration.

跟踪鼠标光标位置、键盘状态和鼠标按钮状态的更改。Changes in the mouse cursor position, keyboard state, and mouse button state are tracked.

  • 如果用户移出一个窗口,则引发 DragLeave 事件。If the user moves out of a window, the DragLeave event is raised.

  • 如果鼠标进入另一个控件,则引发该控件的 DragEnterIf the mouse enters another control, the DragEnter for that control is raised.

  • 如果鼠标移动但停留在同一个控件中,则引发 DragOver 事件。If the mouse moves but stays within the same control, the DragOver event is raised.

如果键盘或鼠标按钮状态,更改QueryContinueDrag事件引发,并确定是否继续拖动、 放置数据,或取消操作值的基础Action属性的事件的QueryContinueDragEventArgsIf there is a change in the keyboard or mouse button state, the QueryContinueDrag event is raised and determines whether to continue the drag, to drop the data, or to cancel the operation based on the value of the Action property of the event's QueryContinueDragEventArgs.

  • 如果的值DragActionContinue,则DragOver引发事件以继续操作并GiveFeedback事件以产生新效果,从而可以设置适当的可视反馈。If the value of DragAction is Continue, the DragOver event is raised to continue the operation and the GiveFeedback event is raised with the new effect so appropriate visual feedback can be set. 有关有效放置效果的列表,请参见 DragDropEffects 枚举。For a list of valid drop effects, see the DragDropEffects enumeration.

    备注

    DragOverGiveFeedback事件成对发生,以便当鼠标移到放置目标时,用户提供的最新反馈有关鼠标的位置。The DragOver and GiveFeedback events are paired so that as the mouse moves across the drop target, the user is given the most up-to-date feedback on the mouse's position.

  • 如果的值DragActionDrop,则放置效果值将返回到源,以便源应用程序可以执行相应的操作对源数据中; 例如,如果则剪切数据是移动操作。If the value of DragAction is Drop, the drop effect value is returned to the source, so the source application can perform the appropriate operation on the source data; for example, cut the data if the operation was a move.

  • 如果的值DragActionCancel,则DragLeave引发事件。If the value of DragAction is Cancel, the DragLeave event is raised.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于

另请参阅