다음을 통해 공유


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

업데이트: 2007년 11월

그림을 만들려면 GraphicsPath를 만든 다음 AddLineAddCurve와 같은 메서드를 호출하여 기본 요소를 경로에 추가합니다.

예제

다음 코드 예제에서는 다음과 같이 그림이 포함된 경로를 만듭니다.

  • 첫 번째 예제에서는 그림이 한 개 포함된 경로를 만듭니다. 이 그림은 원호 한 개로 이루어집니다. 원호의 전진 각도는 기본 좌표계에서 시계 반대 방향으로 180도입니다.

  • 두 번째 예제에서는 그림이 두 개 포함된 경로를 만듭니다. 첫 번째 그림은 원호와 선이 연결되어 구성되고, 두 번째 그림은 선, 곡선, 선이 차례로 연결되어 구성됩니다. 첫 번째 그림은 왼쪽이 열려 있고 두 번째 그림은 닫혀 있습니다.

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)

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);
' 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)

     // 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);

코드 컴파일

앞의 예제는 Windows Forms에서 사용해야 하며 Paint 이벤트 처리기의 매개 변수인 PaintEventArgs e를 필요로 합니다.

참고 항목

참조

GraphicsPath

기타 리소스

경로 구성 및 그리기

펜을 사용하여 선과 도형 그리기