ItemDragEventArgs.Button 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會得到一個值,表示拖曳操作時按下了哪些滑鼠按鍵。
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,隨後會連同一個表示拖放操作期望效果的值一併傳給控制TreeViewDoDragDrop方法。
完整範例請參見 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
備註
這個特性讓你能判斷拖放操作時按下了哪些滑鼠按鈕。 此特性的值可用來正確判斷拖放操作的執行方式。 例如,你可能想在按下滑鼠左鍵時移動物品到新位置,按下右鍵時複製到新位置。