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.

  • 如果滑鼠進入另一個控制項,便會引發該控制項的 DragEnter 事件。If 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.

適用於

另請參閱