Прочетете на английски Редактиране

Споделяне чрез


MouseEventArgs.Button Property

Definition

Gets which mouse button was pressed.

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

Property Value

One of the MouseButtons values.

Examples

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. This example requires that you have a form that contains a TextBox control named textBox1.

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

Applies to

Продукт Версии
.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

See also