Export (0) Print
Expand All

ItemDragEventArgs.Button Property

Gets the name of the mouse button that was clicked during the drag operation.

[Visual Basic]
Public ReadOnly Property Button As MouseButtons
[C#]
public MouseButtons Button {get;}
[C++]
public: __property MouseButtons get_Button();
[JScript]
public function get Button() : MouseButtons;

Property Value

One of the MouseButtons values.

Remarks

This property enables you to determine which mouse button was 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.

Example

[Visual Basic, C#, C++] 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 System.Windows.Forms.TreeView.DoDragDrop method, along with a value that indicates the desired effect of the drag-and-drop operation.

[Visual Basic, C#, C++] For the complete example, see the TreeView.ItemDrag reference topic.

[Visual Basic] 
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 'treeView1_ItemDrag

[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);
    }
}

[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);
        }
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ItemDragEventArgs Class | ItemDragEventArgs Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft