방법: .NET Framework로 도형 그리기

다음 코드 예제에서는 Graphics 클래스를 사용하여 OnPaint 이벤트 처리기를 수정하고 기본 폼의 Graphics 개체에 대한 포인터를 검색합니다.그런 다음 이 포인터를 사용하여 폼의 배경색을 설정하고 Graphics.DrawLineDrawArc 메서드를 사용하여 직선과 원호를 그립니다.

[!참고]

GDI+는 Windows XP에 포함되어 있으며 Windows NT 4.0 SP 6, Windows 2000, Windows 98 및 Windows Me를 위한 재배포 가능 파일로도 구할 수 있습니다.이 재배포 가능 파일의 최신 버전은 https://go.microsoft.com/fwlink/?linkid=11232에서 다운로드할 수 있습니다.자세한 내용은 GDI+를 참조하십시오.

예제

#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
// ...
protected: 
virtual Void Form1::OnPaint(PaintEventArgs^ pe ) override
{
   Graphics^ g = pe->Graphics;
   g->Clear(Color::AntiqueWhite);

   Rectangle rect = Form::ClientRectangle;
   Rectangle smallRect;
   smallRect.X = rect.X + rect.Width / 4;
   smallRect.Y = rect.Y + rect.Height / 4;
   smallRect.Width = rect.Width / 2;
   smallRect.Height = rect.Height / 2;

   Pen^ redPen = gcnew Pen(Color::Red);
   redPen->Width = 4;
   g->DrawLine(redPen, 0, 0, rect.Width, rect.Height);

   Pen^ bluePen = gcnew Pen(Color::Blue);
   bluePen->Width = 10;
   g->DrawArc( bluePen, smallRect, 90, 270 );
}

참고 항목

참조

System::Drawing 네임스페이스

기타 리소스

.Visual C++에서 NET 프로그래밍