다음을 통해 공유


방법: 선, 곡선 및 도형으로 그림 만들기

그림을 만들려면 GraphicsPath를 생성한 다음, 메서드(예: AddLineAddCurve)를 호출하여 경로에 기본 형식을 추가합니다.

예제

다음 코드 예제에서는 그림이 있는 경로를 만듭니다.

  • 첫 번째 예제에서는 단일 그림이 있는 경로를 만듭니다. 그림은 단일 호로 구성됩니다. 호는 기본 좌표계에서 시계 반대 방향인 -180도의 스윕 각도를 가집니다.

  • 두 번째 예제에서는 두 개의 그림이 있는 경로를 만듭니다. 첫 번째 그림에서는 호 뒤에 선이 있습니다. 두 번째 그림에서는 선 다음에 곡선이 오고 선이 옵니다. 첫 번째 그림이 열려 있고 두 번째 그림이 닫힙니다.

GraphicsPath path = new GraphicsPath();
path.AddArc(175, 50, 50, 50, 0, -180);
e.Graphics.DrawPath(new Pen(Color.FromArgb(128, 255, 0, 0), 4), path);
Dim path As New GraphicsPath()
path.AddArc(175, 50, 50, 50, 0, -180)
e.Graphics.DrawPath(New Pen(Color.FromArgb(128, 255, 0, 0), 4), path)

     // Create an array of points for the curve in the second figure.
     Point[] points = {
new Point(40, 60),
new Point(50, 70),
new Point(30, 90)};

     GraphicsPath path = new GraphicsPath();

     path.StartFigure(); // Start the first figure.
     path.AddArc(175, 50, 50, 50, 0, -180);
     path.AddLine(100, 0, 250, 20);
     // First figure is not closed.

     path.StartFigure(); // Start the second figure.
     path.AddLine(50, 20, 5, 90);
     path.AddCurve(points, 3);
     path.AddLine(50, 150, 150, 180);
     path.CloseFigure(); // Second figure is closed.

     e.Graphics.DrawPath(new Pen(Color.FromArgb(255, 255, 0, 0), 2), path);
' Create an array of points for the curve in the second figure.
Dim points As Point() = { _
   New Point(40, 60), _
   New Point(50, 70), _
   New Point(30, 90)}

Dim path As New GraphicsPath()

path.StartFigure() ' Start the first figure.
path.AddArc(175, 50, 50, 50, 0, -180)
path.AddLine(100, 0, 250, 20)
' First figure is not closed.

path.StartFigure() ' Start the second figure.
path.AddLine(50, 20, 5, 90)
path.AddCurve(points, 3)
path.AddLine(50, 150, 150, 180)
path.CloseFigure() ' Second figure is closed.
e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 2), path)

코드 컴파일

이전 예는 Windows Forms와 함께 사용하도록 설계되었으며 Paint 이벤트 처리기의 매개 변수인 PaintEventArgse가 필요합니다.

참고 항목