MouseEventArgs.Location MouseEventArgs.Location MouseEventArgs.Location MouseEventArgs.Location Property


마우스 이벤트를 생성하는 동안 마우스의 위치를 가져옵니다.Gets the location of the mouse during the generating mouse event.

 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

속성 값

양식의 왼쪽 위를 기준으로 마우스의 X 및 Y 좌표(픽셀 단위)를 포함하는 Point입니다.A Point that contains the x- and y- mouse coordinates, in pixels, relative to the upper-left corner of the form.


다음 코드 예제에서는 Location 속성을 마우스 왼쪽된 단추 클릭을 추적 하 고 사용자 입력에 대 한 응답에는 일련의 직선 세그먼트를 그립니다.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. 이 예제에서는 폼을 숨기고,를 다시 표시 하는 경우 그려지는 선은 유지 되지 않습니다. 이 코드는 편의상 생략 되었습니다.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;
        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
        FirstPoint = e.Location
        HaveFirstPoint = True
    End If
End Sub

적용 대상

추가 정보