Compartir a través de


Cómo: Dibujar formas con .NET Framework (C++/CLI)

El ejemplo de código siguiente utiliza la clase Graphics para modificar el controlador de eventos OnPaint para recuperar un puntero al objeto Graphics para el formulario principal. Este puntero se utiliza posteriormente para establecer el color de fondo del formulario y dibujar una línea y un arco utilizando los métodos Graphics.DrawLine y DrawArc.

Nota

GDI+ se incluye con Windows XP y está disponible como componente redistribuible con Windows NT 4.0 SP 6, Windows 2000, Windows 98 y Windows Me. Para descargar el último redistribuible, vea https://go.microsoft.com/fwlink/?linkid=11232. Para obtener más información, vea GDI+.

Ejemplo

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

Vea también

Referencia

System::Drawing (Espacio de nombres)

Otros recursos

Guía de programación de .NET