ToolStripItem.QueryContinueDrag 事件

定義

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

public:
 event System::Windows::Forms::QueryContinueDragEventHandler ^ QueryContinueDrag;
[System.ComponentModel.Browsable(false)]
public event System.Windows.Forms.QueryContinueDragEventHandler QueryContinueDrag;
[System.ComponentModel.Browsable(false)]
public event System.Windows.Forms.QueryContinueDragEventHandler? QueryContinueDrag;
[<System.ComponentModel.Browsable(false)>]
member this.QueryContinueDrag : System.Windows.Forms.QueryContinueDragEventHandler 
Public Custom Event QueryContinueDrag As QueryContinueDragEventHandler 

事件類型

屬性

範例

下列程式碼範例示範如何使用這個成員。 在此範例中,事件處理常式會報告事件的發生次數 QueryContinueDrag 。 此報告可協助您瞭解事件發生的時間,並可協助您進行偵錯。 若要報告多個事件或經常發生的事件,請考慮將 取代 MessageBox.ShowConsole.WriteLine 或將訊息附加至多行 TextBox

若要執行範例程式碼,請將它貼入包含繼承自 ToolStripItem 之型別實例的專案,例如 ToolStripButtonToolStripMenuItem 。 然後命名 實例 ToolStripItem1 ,並確定事件處理常式與 事件相關聯 QueryContinueDrag

private void ToolStripItem1_QueryContinueDrag(Object sender, QueryContinueDragEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "KeyState", e.KeyState );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "EscapePressed", e.EscapePressed );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "QueryContinueDrag Event" );
}
Private Sub ToolStripItem1_QueryContinueDrag(sender as Object, e as QueryContinueDragEventArgs) _ 
     Handles ToolStripItem1.QueryContinueDrag

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "KeyState", e.KeyState)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "EscapePressed", e.EscapePressed)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"QueryContinueDrag Event")

End Sub

備註

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

下列備註說明如何及何時引發與拖放作業相關的事件。

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

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

滑鼠游標位置、鍵盤狀態和滑鼠按鍵狀態的變更會以下列方式追蹤:

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

  • 如果滑鼠進入另一個專案, DragEnter 則會引發該控制項的 。

  • 如果滑鼠移動但停留在相同的專案內,就會 DragOver 引發 事件。

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

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

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

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

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

適用於