2-D Graphics Programming with GDI+
The Windows operating system has always included support for drawing two-dimensional graphics. This support is known as the Graphics Device Interface (GDI) library. The GDI library is now easier to use and provides additional features. The new capabilities are known collectively as GDI+. GDI+ features are exposed in the .NET Framework through classes in the System.Drawing, System.Drawing.Drawing2D, System.Drawing.Imaging, and System.Drawing.Text namespaces. This section discusses some of those capabilities.
The Graphics Class
Objects of type Graphics (defined in the System.Drawing namespace) represent two-dimensional surfaces on which to draw. A Graphics object must be obtained before any drawing can be done. A common way to obtain a Graphics object is to override the OnPaint method of a form or user control, as shown in the following code fragment:
Public Class MyControl
Inherits UserControl
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.FillEllipse(New SolidBrush(Me.ForeColor), _
Me.ClientRectangle)
End Sub
Public Sub New( )
Me.ResizeRedraw = True
End Sub
End ClassThe single argument passed to the OnPaint method,
e, is of type PaintEventArgs. This class
has a property called Graphics, which holds a reference to the
Graphics object to be used for drawing on the user control or form.
The PaintEventArgs class is defined in the
System.Windows.Forms namespace. It has two
properties:
- ClipRectangle
Defines the area that needs ...