Control.QueryContinueDrag 事件

定義

發生於拖放作業時,讓拖曳來源能夠決定是否應取消拖放作業。

C#
public event System.Windows.Forms.QueryContinueDragEventHandler QueryContinueDrag;
C#
public event System.Windows.Forms.QueryContinueDragEventHandler? QueryContinueDrag;

事件類型

範例

如果拖曳作業在表單界限外移動,此程式碼摘錄示範如何使用 QueryContinueDrag 事件取消拖放作業。 如需完整的程式碼範例, DoDragDrop 請參閱 方法。

C#
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;
        }
    }
}

備註

QueryContinueDrag當拖放作業期間鍵盤或滑鼠按鍵狀態有所變更時,就會引發 事件。 事件 QueryContinueDrag 可讓拖曳來源判斷是否應該取消拖放作業。

以下描述與拖放作業相關的事件,其引發的方法與時機。

方法 DoDragDrop 會決定目前游標位置下的 控制項。 然後,它會檢查控制項是否為有效的置放目標。

如果控制項是有效的置放目標,則會 GiveFeedback 使用指定的拖放效果引發事件。 如需拖放效果的清單,請參閱 DragDropEffects 列舉型別。

系統會追蹤滑鼠游標位置、鍵盤狀態和滑鼠按鈕狀態的變更。

  • 如果使用者移出視窗外,便會引發 DragLeave 事件。

  • 如果滑鼠進入另一個控制項,便會引發該控制項的 DragEnter 事件。

  • 如果滑鼠移動,但是待在相同的控制項內,便會引發 DragOver 事件。

如果鍵盤或滑鼠按鍵狀態有變更, QueryContinueDrag 則會引發 事件,並判斷是否要繼續拖曳、卸載資料,或根據 Action 事件的 QueryContinueDragEventArgs 屬性值取消作業。

  • 如果 的值為 DragActionContinue ,則會 DragOver 引發 事件以繼續作業,並以 GiveFeedback 新的效果引發 事件,以便設定適當的視覺回饋。 如需有效置放效果的清單,請參閱 DragDropEffects 列舉型別。

    注意

    DragOverGiveFeedback 事件會配對,如此一來,當滑鼠在置放目標上移動時,系統會提供使用者對滑鼠位置的最新意見反應。

  • 如果 的值為 DragActionDrop ,則會將置放效果值傳回至來源,讓來源應用程式可以在來源資料上執行適當的作業;例如,如果作業是移動,請剪下資料。

  • 如果 的 DragActionCancel 值為 ,則會 DragLeave 引發 事件。

根據預設, QueryContinueDrag 如果按下 ESC 鍵,事件會設定 ActionCancelDragAction 為 ,並在按下左鍵、中間鍵或滑鼠右鍵時設定 Action 為 。 DragActionDrop

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱