ToolStripItem.DragEnter 事件

定義

發生於使用者將項目拖入這個項目的工作區 (Client Area) 時。

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

事件類型

屬性

範例

下列程式碼範例示範如何將 和 Y 屬性轉換成 X 用戶端 Point 。 此程式碼範例是提供給 類別之較大範例的 ToolStripRenderer 一部分。

// This method defines the DragOver event behavior. 
protected override void OnDragOver(DragEventArgs dea)
{
    base.OnDragOver(dea);

    // Get the ToolStripButton control 
    // at the given mouse position.
    Point p = new Point(dea.X, dea.Y);
    ToolStripButton item = this.GetItemAt(
        this.PointToClient(p)) as ToolStripButton;

    // If the ToolStripButton control is the empty cell,
    // indicate that the move operation is valid.
    if( item == this.emptyCellButton )
    {
        // Set the drag operation to indicate a valid move.
        dea.Effect = DragDropEffects.Move;
    }
}
' This method defines the DragOver event behavior. 
Protected Overrides Sub OnDragOver(dea As DragEventArgs)
   MyBase.OnDragOver(dea)
   
   ' Get the ToolStripButton control 
   ' at the given mouse position.
   Dim p As New Point(dea.X, dea.Y)
   Dim item As ToolStripButton = CType(Me.GetItemAt(Me.PointToClient(p)), ToolStripButton)
   
   
   ' If the ToolStripButton control is the empty cell,
   ' indicate that the move operation is valid.
     If item Is Me.emptyCellButton Then
         ' Set the drag operation to indicate a valid move.
         dea.Effect = DragDropEffects.Move
     End If
 End Sub

備註

當使用者 DragEnter 第一次在拖放作業期間將滑鼠游標拖曳到專案上方時,就會引發 事件。

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

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

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

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

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

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

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

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

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

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

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

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

注意

XDragEventArgsY 屬性位於螢幕座標中,而不是用戶端座標。

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

適用於