ItemDragEventArgs.Button Property

Definition

Gets a value that indicates which mouse buttons were pressed during the drag operation.

C#
public System.Windows.Forms.MouseButtons Button { get; }

Property Value

A bitwise combination of MouseButtons values.

Examples

The following example illustrates the use of the ItemDragEventArgs class when you enable drag-and-drop operations within a TreeView control. The Button property determines whether the dragged node should be moved or copied to its destination. The node, represented by the Item property, is then passed to the TreeView control's DoDragDrop method, along with a value that indicates the desired effect of the drag-and-drop operation.

For the complete example, see the TreeView.ItemDrag reference topic.

C#
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);
    }
}

Remarks

This property enables you to determine which mouse buttons were pressed during a drag-and-drop operation. The value of this property can be used to properly determine how the drag-and drop-operation should be performed. For example, you might want to move an item to a new location when the left mouse button is pressed, and copy it to the new location when the right mouse button is pressed.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10