MouseEventArgs.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 值。

範例

下列程式碼範例會處理 MouseDown 控制項上的 TextBox 事件,讓按一下滑鼠右鍵會選取控制項中的所有文字。 此範例需要您有一個表單,其中包含 TextBox 名為 的 textBox1 控制項。

private void Form1_Load(object sender, EventArgs e)
{
    // This line suppresses the default context menu for the TextBox control. 
    textBox1.ContextMenu = new ContextMenu();
    textBox1.MouseDown += new MouseEventHandler(textBox1_MouseDown);
}

void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        textBox1.Select(0, textBox1.Text.Length);
    }
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.ContextMenu = New ContextMenu()
End Sub

Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
    If (e.Button = Windows.Forms.MouseButtons.Right) Then
        TextBox1.Select(0, TextBox1.Text.Length)
    End If
End Sub

適用於

另請參閱