ToolStripItem.DragDrop 活动
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当用户拖动某个项并且用户释放鼠标按钮时发生,指示该项应放入此项。
public:
event System::Windows::Forms::DragEventHandler ^ DragDrop;
[System.ComponentModel.Browsable(false)]
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
事件类型
- 特性
示例
下面的代码示例演示如何将 X 属性 Y 转换为客户端 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其Y属性DragEventArgs位于屏幕坐标中,而不是客户端坐标。 有关处理事件的详细信息,请参阅 处理和引发事件。