Como: desenhar formas com o.NET Framework

O seguinte exemplo de código usa o Graphics classe para modificar o OnPaint manipulador de eventos para recuperar um ponteiro para o Graphics o objeto para o formulário principal.Esse ponteiro é usado para definir a cor de fundo do formulário e desenhe uma linha e um arco usando o Graphics.DrawLine e DrawArc métodos.

ObservaçãoObservação

GDI+ é incluído no Windows XP e está disponível como um redistribuível para Windows NT 4.0 SP 5, Windows 2000, Windows 98 e Windows Me.Para baixar o mais recente redistribuível, consulte https://go.microsoft.com/fwlink/?linkid=11232.Para obter mais informações, consulte GDI+.

Exemplo

#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 );
}

Consulte também

Referência

Namespace System::Drawing

Outros recursos

.NET programação no Visual C++