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 值的位元組合。

範例

下列範例說明當您在控制項內 TreeView 啟用拖放作業時, ItemDragEventArgs 類別的使用方式。 屬性 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

備註

此屬性可讓您判斷拖放作業期間按下的滑鼠按鍵。 這個屬性的值可用來正確判斷應該如何執行拖放作業。 例如,您可能想要在按下滑鼠左鍵時,將專案移至新位置,並在按下滑鼠右鍵時將其複製到新位置。

適用於