共用方式為


Control.QueryContinueDrag 事件

定義

發生在拖放操作期間,使拖曳源判斷是否應該取消拖放操作。

public:
 event System::Windows::Forms::QueryContinueDragEventHandler ^ QueryContinueDrag;
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 事件取消拖放操作。 完整程式碼範例請參見方法。DoDragDrop

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, 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, 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當拖放操作中鍵盤或滑鼠按鈕狀態發生變化時,事件會被觸發。 此 QueryContinueDrag 事件使拖曳源判斷是否應取消拖放操作。

以下說明與拖放操作相關的事件是如何以及何時被提出的。

此方法決定 DoDragDrop 在當前游標位置下的控制。 接著檢查控制點是否為有效的投放目標。

若控制點為有效的投放目標, GiveFeedback 事件會觸發並指定拖放效果。 拖放效果列表請參見 DragDropEffects 列舉。

滑鼠游標位置、鍵盤狀態及滑鼠按鈕狀態的變化都會被追蹤。

  • 如果使用者移出視窗, DragLeave 事件就會被觸發。

  • 若滑鼠進入另一個控制項,該控制項的 會 DragEnter 提高。

  • 如果滑鼠移動但仍停留在同一控制範圍內, DragOver 事件會被觸發。

若鍵盤或滑鼠按鈕狀態有變化,QueryContinueDrag事件會被觸發,並根據事件QueryContinueDragEventArgs屬性的值Action決定是否繼續拖曳、資料下放或取消操作。

  • DragAction 值為 ContinueDragOver 則事件會被觸發以繼續操作,並 GiveFeedback 以新效果觸發事件,以便設定適當的視覺回饋。 有關有效落差效應的列表,請參閱列舉。DragDropEffects

    備註

    DragOverGiveFeedback事件會配對,當滑鼠移動到落點時,使用者會獲得最多 up-to-日期的滑鼠位置回饋。

  • 若 的值 DragActionDrop,則 drop effect 值會回傳給來源資料,因此來源應用程式可以對來源資料執行適當的操作;例如,如果操作是移動,則會切割資料。

  • 若 值 DragActionCancelDragLeave 則事件會被觸發。

預設情況下,如果按下 ESC 鍵,事件QueryContinueDrag會設ActionCancel為 inDragAction;按下滑鼠左、中、右鍵則設ActionDrop inDragAction

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱