ItemDragEventArgs.Button 属性

获取一个值,该值指示在拖动操作过程中按下的鼠标按钮。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public ReadOnly Property Button As MouseButtons
用法
Dim instance As ItemDragEventArgs
Dim value As MouseButtons

value = instance.Button
public MouseButtons Button { get; }
public:
property MouseButtons Button {
    MouseButtons get ();
}
/** @property */
public MouseButtons get_Button ()
public function get Button () : MouseButtons

属性值

MouseButtons 值的按位组合。

备注

使用该属性可确定在拖放操作过程中按下的鼠标按钮。可使用该属性的值正确地确定应如何执行拖放操作。例如,按下鼠标左键可以将某项移动到一个新位置,而按下鼠标右键则将其复制到该新位置。

示例

下面的示例阐释了在 TreeView 控件中启用拖放操作时,如何使用 ItemDragEventArgs 类。Button 属性确定被拖动的节点应该移动还是复制到其目标。然后节点(由 Item 属性表示)与一个指示所需拖放操作效果的值一起被传递给 TreeView 控件的 DoDragDrop 方法。

有关完整的示例,请参见 TreeView.ItemDrag 参考主题。

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 'treeView1_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 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
      
      // 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.get_Button().Equals(get_MouseButtons().Left)) {
        DoDragDrop(e.get_Item(), DragDropEffects.Move);
    }
    // Copy the dragged node when the right mouse button is used.
    else {
        if (e.get_Button().Equals(get_MouseButtons().Right)) {
            DoDragDrop(e.get_Item(), DragDropEffects.Copy);
        }
    }
} //treeView1_ItemDrag

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ItemDragEventArgs 类
ItemDragEventArgs 成员
System.Windows.Forms 命名空间