MouseEventArgs.Button Propiedad

Definición

Obtiene qué botón del mouse se presionó.Gets which mouse button was pressed.

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

Valor de propiedad

Uno de los valores de MouseButtons.One of the MouseButtons values.

Ejemplos

En el ejemplo de código siguiente se controla el evento de MouseDown en un control TextBox de modo que al hacer clic con el botón secundario del mouse se selecciona todo el texto del control.The following code example handles the MouseDown event on a TextBox control so that clicking the right mouse button selects all the text in the control. Este ejemplo requiere que tenga un formulario que contenga un control TextBox denominado textBox1.This example requires that you have a form that contains a TextBox control named 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

Se aplica a

Consulte también: