Sdílet prostřednictvím


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í do TreeView ovládacího prvku. Vlastnost Button určuje, zda má být přetažen uzel přesunut nebo zkopírován do cíle. Uzel reprezentovaný Item vlastností se pak předá 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 během operace přetažení stisknuta. Hodnotu této vlastnosti lze použít k správnému určení způsobu provedení operace přetažení a přetažení. Pokud je například stisknuto levé tlačítko myši, můžete položku přesunout do nového umístění a po stisknutí pravého tlačítka myši ji zkopírovat do nového umístění.

Platí pro