Share via


ItemDragEventArgs.Button Vlastnost

Definice

Získá hodnotu, která označuje, která tlačítka myši byla stisknuta během operace přetažení.

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

Hodnota vlastnosti

Bitové kombinace MouseButtons hodnot.

Příklady

Následující příklad znázorňuje použití ItemDragEventArgs třídy při povolení operací přetažení v rámci TreeView ovládacího prvku. Vlastnost Button určuje, zda má být přetažený uzel přesunut nebo zkopírován do svého cíle. Uzel, reprezentovaný Item vlastností, je pak předán TreeView metodě ovládacího prvku DoDragDrop spolu s hodnotou, která označuje požadovaný účinek operace přetažení.

Úplný příklad najdete v referenčním TreeView.ItemDrag tématu.

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

Poznámky

Tato vlastnost umožňuje určit, která tlačítka myši byla stisknuta během operace přetažení. Hodnotu této vlastnosti lze použít k správnému určení, jak se má operace přetažení provést. Můžete například chtít přesunout položku na nové místo, když je stisknuto levé tlačítko myši, a zkopírovat ji do nového umístění, když je stisknuto pravé tlačítko myši.

Platí pro