Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

MouseEventArgs Classe

Provides data for the MouseUp, MouseDown, and MouseMove events.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms. dll)

[ComVisibleAttribute(true)]
public class MouseEventArgs : EventArgs

The MouseDown event occurs when the user presses the mouse button while the pointer is over a control.The MouseUp event occurs when the user releases the mouse button while the pointer remains over the control.The MouseMove event occurs when the user moves the mouse pointer over a control.A MouseEventArgs specifies which mouse button is pressed, how many times the mouse button was pressed and released, the coordinates of the mouse, and the amount the mouse wheel moved.

It is possible to receive a MouseDown event without a corresponding MouseUp, if the user switches focus to another application before releasing the mouse button.

These three events exist for the Control, AxHost, and NotifyIcon classes.

For information about the event model, see Eventos e representantes.

The following code examples handles the MouseDown event on a TextBox control so that clicking the right mouse button selects all of the text in the control.This example requires that you have a form with 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);
    }
}


The following code example uses the Location property to track left mouse clicks and draw a series of straight line segments in response to user input.O exemplo não redesenhar as linhas se você ocultar o formulário e, em seguida, reexiba ele; Esse código foi omitido para simplificar.

Point firstPoint;
Boolean haveFirstPoint;

public void EnableDrawing()
{
    this.MouseDown += new MouseEventHandler(Form1_MouseDownDrawing);
}

void Form1_MouseDownDrawing(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (haveFirstPoint)
    {
        Graphics g = this.CreateGraphics();
        g.DrawLine(Pens.Black, firstPoint, e.Location);
        haveFirstPoint = false;
    }
    else
    {
        firstPoint = e.Location;
        haveFirstPoint = true;
    }
}


The following code example uses the X and Y properties to display the current position of the mouse pointer in a ToolTip window.

ToolTip trackTip;

private void TrackCoordinates()
{
    trackTip = new ToolTip();
    this.MouseMove += new MouseEventHandler(Form1_MouseMove);
}

void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    String tipText = String.Format("({0}, {1})", e.X, e.Y);
    trackTip.Show(tipText, this, e.Location);
}


Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Contribuições da comunidade

ADICIONAR
Mostrar: