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表されるノードは、ドラッグ アンド ドロップ操作の目的の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

注釈

このプロパティを使用すると、ドラッグ アンド ドロップ操作中に押されたマウス ボタンを決定できます。 このプロパティの値を使用して、ドラッグ アンド ドロップ操作の実行方法を適切に決定できます。 たとえば、マウスの左ボタンを押したときに項目を新しい場所に移動し、マウスの右ボタンが押されたときに新しい場所にコピーすることができます。

適用対象