ToolStripItem.DragOver 事件

定義

發生於使用者將項目拖過這個項目的工作區時。

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

事件類型

屬性

範例

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

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

private void ToolStripItem1_DragOver(Object sender, DragEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Data", e.Data );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "KeyState", e.KeyState );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "X", e.X );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Y", e.Y );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "AllowedEffect", e.AllowedEffect );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Effect", e.Effect );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "DragOver Event" );
}
Private Sub ToolStripItem1_DragOver(sender as Object, e as DragEventArgs) _ 
     Handles ToolStripItem1.DragOver

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Data", e.Data)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "KeyState", e.KeyState)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "X", e.X)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Y", e.Y)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "AllowedEffect", e.AllowedEffect)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Effect", e.Effect)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"DragOver Event")

End Sub

備註

DragOver當滑鼠游標在拖放作業期間,在控制項界限內移動時,就會引發 事件。

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

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

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

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

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

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

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

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

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

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

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

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

適用於