ItemDragEventArgs.Button 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示拖动操作期间按下了哪些鼠标按钮。
public:
property System::Windows::Forms::MouseButtons Button { System::Windows::Forms::MouseButtons get(); };
public System.Windows.Forms.MouseButtons Button { get; }
member this.Button : System.Windows.Forms.MouseButtons
Public ReadOnly Property Button As MouseButtons
属性值
值的按位组合 MouseButtons 。
示例
以下示例演示在控件中TreeView启用拖放操作时类的使用ItemDragEventArgs。 该 Button 属性确定拖动的节点是应移动还是复制到其目标。 然后,由属性表示Item的DoDragDrop节点将传递给TreeView控件的方法,以及指示拖放操作所需效果的值。
有关完整示例,请参阅 TreeView.ItemDrag 参考主题。
private:
void treeView1_ItemDrag( Object^ /*sender*/, ItemDragEventArgs^ e )
{
// Move the dragged node when the left mouse button is used.
if ( e->Button == ::MouseButtons::Left )
{
DoDragDrop( e->Item, DragDropEffects::Move );
}
// Copy the dragged node when the right mouse button is used.
else
// Copy the dragged node when the right mouse button is used.
if ( e->Button == ::MouseButtons::Right )
{
DoDragDrop( e->Item, DragDropEffects::Copy );
}
}
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
// Move the dragged node when the left mouse button is used.
if (e.Button == MouseButtons.Left)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
// Copy the dragged node when the right mouse button is used.
else if (e.Button == MouseButtons.Right)
{
DoDragDrop(e.Item, DragDropEffects.Copy);
}
}
Private Sub treeView1_ItemDrag(ByVal sender As Object, ByVal e As ItemDragEventArgs)
' Move the dragged node when the left mouse button is used.
If e.Button = MouseButtons.Left Then
DoDragDrop(e.Item, DragDropEffects.Move)
' Copy the dragged node when the right mouse button is used.
ElseIf e.Button = MouseButtons.Right Then
DoDragDrop(e.Item, DragDropEffects.Copy)
End If
End Sub
注解
使用此属性可以确定拖放操作期间按下了哪些鼠标按钮。 此属性的值可用于正确确定应如何执行拖放操作。 例如,在按下鼠标左键时,可能需要将项目移动到新位置,并在按下鼠标右键时将其复制到新位置。