JavaScript EditorDhtml editor     Free javascript download 



Main Page

The following code example uses the Graphics class to modify the OnPaint event handler to retrieve a pointer to the Graphics object for the main form. This pointer is then used to set the background color of the form and draw a line and an arc using the System.Drawing.Graphics.DrawLine and DrawArc methods.

NoteNote

GDI+ is included with WindowsВ XP and is available as a redistributable for WindowsВ NT 4.0 SP 6, WindowsВ 2000, WindowsВ 98, and WindowsВ Me. To download the latest redistributable, see http://go.microsoft.com/fwlink?lin. For more information, see GDI+.

Example

В CopyCode imageCopy Code
#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
// ...
protected: 
Void Form1::OnPaint(PaintEventArgs^ pe ) 
{
   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 );
}

See Also

Reference

System::Drawing namespace

Other Resources

.NET Programming in C++



JavaScript EditorDhtml editor     Free javascript download