Control.QueryContinueDrag Control.QueryContinueDrag Control.QueryContinueDrag Control.QueryContinueDrag Event

定义

在拖放操作期间发生,并且允许拖动源确定是否应取消拖放操作。Occurs during a drag-and-drop operation and enables the drag source to determine whether the drag-and-drop operation should be canceled.

public:
 event System::Windows::Forms::QueryContinueDragEventHandler ^ QueryContinueDrag;
public event System.Windows.Forms.QueryContinueDragEventHandler QueryContinueDrag;
member this.QueryContinueDrag : System.Windows.Forms.QueryContinueDragEventHandler 
Public Custom Event QueryContinueDrag As QueryContinueDragEventHandler 

示例

这段代码摘录演示了如何使用QueryContinueDrag事件取消拖放操作,如果拖放操作移动窗体的界限外。This code excerpt demonstrates using the QueryContinueDrag event to cancel the drag-and-drop operation if the drag operation moves outside the bounds of the form. 请参阅DoDragDrop完整的代码示例的方法。See the DoDragDrop method for the complete code example.

void ListDragSource_QueryContinueDrag( Object^ sender, System::Windows::Forms::QueryContinueDragEventArgs^ e )
{
   // Cancel the drag if the mouse moves off the form.
   ListBox^ lb = dynamic_cast<ListBox^>(sender);
   if ( lb != nullptr )
   {
      Form^ f = lb->FindForm();

      // Cancel the drag if the mouse moves off the form. The screenOffset
      // takes into account any desktop bands that may be at the top or left
      // side of the screen.
      if ( ((Control::MousePosition.X - screenOffset.X) < f->DesktopBounds.Left) || ((Control::MousePosition.X - screenOffset.X) > f->DesktopBounds.Right) || ((Control::MousePosition.Y - screenOffset.Y) < f->DesktopBounds.Top) || ((Control::MousePosition.Y - screenOffset.Y) > f->DesktopBounds.Bottom) )
      {
         e->Action = DragAction::Cancel;
      }
   }
}
private void ListDragSource_QueryContinueDrag(object sender, System.Windows.Forms.QueryContinueDragEventArgs e) {
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = sender as ListBox;

    if (lb != null) {

        Form f = lb.FindForm();

        // Cancel the drag if the mouse moves off the form. The screenOffset
        // takes into account any desktop bands that may be at the top or left
        // side of the screen.
        if (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) ||
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) ||
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) ||
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) {

            e.Action = DragAction.Cancel;
        }
    }
}
Private Sub ListDragSource_QueryContinueDrag(ByVal sender As Object, ByVal e As QueryContinueDragEventArgs) Handles ListDragSource.QueryContinueDrag
    ' Cancel the drag if the mouse moves off the form.
    Dim lb as ListBox = CType(sender, System.Windows.Forms.ListBox)

    If (lb isNot nothing) Then

        Dim f as Form = lb.FindForm()

        ' Cancel the drag if the mouse moves off the form. The screenOffset
        ' takes into account any desktop bands that may be at the top or left
        ' side of the screen.
        If (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) Or _
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) Or _
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) Or _
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) Then

            e.Action = DragAction.Cancel
        End If
    End if
End Sub

注解

QueryContinueDrag拖放操作期间键盘或鼠标按钮状态更改时引发事件。The QueryContinueDrag event is raised when there is a change in the keyboard or mouse button state during a drag-and-drop operation. QueryContinueDrag事件允许拖动源确定是否应取消拖放操作。The QueryContinueDrag event enables the drag source to determine whether the drag-and-drop operation should be canceled.

下面描述与拖放操作相关的事件的引发方式以及引发时间。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.

默认情况下QueryContinueDrag事件将设置ActionCancelDragAction如果按下了 ESC 键,并设置ActionDropDragAction如果按下鼠标左键、 中间名或右按钮。By default, the QueryContinueDrag event sets Action to Cancel in DragAction if the ESC key was pressed and sets Action to Drop in DragAction if the left, middle, or right mouse button is pressed.

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

适用于

另请参阅