MouseEventArgs.Location Propriedade

Definição

Obtém o local do mouse durante o evento de geração do mouse.Gets the location of the mouse during the generating mouse event.

public:
 property System::Drawing::Point Location { System::Drawing::Point get(); };
public System.Drawing.Point Location { get; }
member this.Location : System.Drawing.Point
Public ReadOnly Property Location As Point

Valor da propriedade

Um Point que contém as coordenadas de x e y do mouse, em pixels, relativas ao canto superior esquerdo da tela.A Point that contains the x- and y- mouse coordinates, in pixels, relative to the upper-left corner of the form.

Exemplos

O exemplo de código a seguir Location usa a propriedade para rastrear os cliques do mouse esquerdo e desenha uma série de segmentos de linha reta em resposta à entrada do usuário.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 manterá as linhas desenhadas se você ocultar o formulário e, em seguida, reexibi-lo; Esse código foi omitido para simplificação.The example does not persist the drawn lines if you hide the form and then redisplay it; this code was omitted for simplicity.

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;
    }
}
Dim FirstPoint As Point
Dim HaveFirstPoint As Boolean = False

Private Sub Form1_MouseDownDrawing(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    If HaveFirstPoint Then
        Dim g As Graphics = Me.CreateGraphics()
        g.DrawLine(Pens.Black, FirstPoint, e.Location)
        HaveFirstPoint = False
    Else
        FirstPoint = e.Location
        HaveFirstPoint = True
    End If
End Sub

Aplica-se a

Veja também