ItemDragEventArgs.Button Свойство

Определение

Возвращает значение, указывающее, какие кнопки мыши были нажаты во время операции перетаскивания.

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 .

Примеры

В следующем примере показано использование ItemDragEventArgs класса при включении операций перетаскивания в элементе TreeView управления. Свойство Button определяет, следует ли переместить или скопировать перетаскиваемый узел в место назначения. Затем узел, представленный Item свойством, передается TreeView методу элемента управления DoDragDrop , а также значение, указывающее требуемый эффект операции перетаскивания.

Полный пример см. в справочном 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

Комментарии

Это свойство позволяет определить, какие кнопки мыши были нажаты во время операции перетаскивания. Значение этого свойства можно использовать для правильного определения способа выполнения операции перетаскивания. Например, может потребоваться переместить элемент в новое расположение при нажатии левой кнопки мыши и скопировать его в новое расположение при нажатии правой кнопки мыши.

Применяется к