共用方式為


ToolStripItem.DragDrop 事件

定義

發生於使用者拖曳項目以及釋放滑鼠按鈕時,表示項目應該放入這個項目中。

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

事件類型

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

備註

X DragEventArgsY 屬性位於螢幕座標中,而不是用戶端座標。 如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於