ToolStripItem.QueryContinueDrag 事件


發生於拖放作業時,允許拖曳來源決定是否應取消拖放作業。Occurs during a drag-and-drop operation and allows the drag source to determine whether the drag-and-drop operation should be canceled.

 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 


下列程式碼範例示範如何使用這個成員。The following code example demonstrates the use of this member. 在此範例中,事件處理常式會報告 QueryContinueDrag 事件的發生。In the example, an event handler reports on the occurrence of the QueryContinueDrag event. 此報表可協助您瞭解事件發生的時間,並可協助您進行調試。This report helps you to learn when the event occurs and can assist you in debugging. 若要報告多個事件或經常發生的事件,請考慮使用 Console.WriteLine 取代 MessageBox.Show,或將訊息附加到多行 TextBoxTo report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要執行範例程式碼,請將它貼入包含繼承自 ToolStripItem之類型實例的專案,例如 ToolStripButtonToolStripMenuItemTo run the example code, paste it into a project that contains an instance of a type that inherits from ToolStripItem, such as a ToolStripButton or ToolStripMenuItem. 然後將實例命名為 ToolStripItem1,並確定事件處理常式與 QueryContinueDrag 事件相關聯。Then name the instance ToolStripItem1 and ensure that the event handler is associated with the QueryContinueDrag event.

private void ToolStripItem1_QueryContinueDrag(Object sender, QueryContinueDragEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "KeyState", e.KeyState );
messageBoxCS.AppendFormat("{0} = {1}", "EscapePressed", e.EscapePressed );
messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action );
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.AppendFormat("{0} = {1}", "EscapePressed", e.EscapePressed)
    messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
    MessageBox.Show(messageBoxVB.ToString(),"QueryContinueDrag Event")

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 allows the drag source to determine whether the drag-and-drop operation should be canceled.

下列備註描述與拖放作業相關之事件的引發方式和時機。The following remarks describe how and when events related to drag-and-drop operations are raised.

DoDragDrop 方法會決定目前資料指標位置底下的專案。The DoDragDrop method determines the item under the current cursor location. 然後,它會檢查項目是否為有效的放置目標。It then checks to see if the item is a valid drop target.

如果專案是有效的放置目標,則會以指定的拖放效果來引發 GiveFeedback 事件。If the item 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 in the following manner:

  • 如果使用者移出視窗外,便會引發 DragLeave 事件。If the user moves out of a window, the DragLeave event is raised.

  • 如果滑鼠進入另一個專案,則會引發該控制項的 DragEnterIf the mouse enters another item, the DragEnter for that control is raised.

  • 如果滑鼠移動但停留在同一個專案中,就會引發 DragOver 事件。If the mouse moves but stays within the same item, the DragOver event is raised.

如果鍵盤或滑鼠按鍵狀態有變更,就會引發 QueryContinueDrag 事件,並決定是否要繼續拖曳、卸載資料,或根據事件 QueryContinueDragEventArgsAction 屬性值來取消作業。If 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.

如果 DragAction 的值為 Continue,則會引發 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, as follows:

  • 如果 DragAction 的值為 Drop,卸載效果值就會傳回來源,因此來源應用程式可以對來源資料執行適當的作業。例如,如果作業是移動,則剪下資料。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.

  • 如果 DragAction 的值為 Cancel,則會引發 DragLeave 事件。If the value of DragAction is Cancel, the DragLeave event is raised.