MouseEventArgs.Location 속성

정의

마우스 이벤트를 생성하는 동안 마우스의 위치를 가져옵니다.

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

속성 값

Point

컨트롤의 왼쪽 위 모서리를 기준으로 x-및 y-마우스 좌표를 픽셀 단위로 포함하는 A Point 입니다.

예제

다음 코드 예제에서는 속성을 사용하여 Location 마우스 왼쪽 클릭을 추적하고 사용자 입력에 대한 응답으로 일련의 직선 세그먼트를 그립니다. 이 예제에서는 폼을 숨기고 다시 표시하면 그려진 선을 유지하지 않습니다. 이 코드는 간단히 하기 위해 생략되었습니다.

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

적용 대상

추가 정보