The Graphics Class 2-D Graphics Programming with GDI+

160 Indicates whether a property is read-only at design time. Specify ReadOnlyTrue to indicate that the property is read-only at design time. Specify ReadOnlyFalse to indicate that the propertys ability to be modified at design time is determined by whether a Set method is defined for the property. Omitting the attribute is the same as specifying ReadOnlyFalse . RecommendedAsConfigurableAttribute Indicates whether a property is configurable. Configurable properties arent discussed in this book. RefreshPropertiesAttribute Determines how the Properties window is refreshed when the value of the given property changes. RunInstallerAttribute Indicates whether an installer should be invoked during installation of the assembly that contains the associated class. This attribute can be used only on class declarations, and the associated class must inherit from the Installer class defined in the System.Configuration.Install namespace. Installers are not discussed in this book. ToolboxItemAttribute Specifies a type that implements a toolbox item related to the declaration on which the attribute is placed. This facility is not discussed in this book. ToolboxItemFilterAttribute Specifies a filter string for a toolbox-item filter. This facility is not discussed in this book. TypeConverterAttribute Indicates the type converter to be used with the associated item. Type converters are not discussed in this book. 4.6 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.

4.6.1 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 161 Protected Overrides Sub OnPaintByVal e As PaintEventArgs e.Graphics.FillEllipseNew SolidBrushMe.ForeColor, _ Me.ClientRectangle End Sub Public Sub New Me.ResizeRedraw = True End Sub End Class The 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 to be drawn. Drawing done outside the limits of the clip rectangle will not be displayed. The coordinates of the rectangle are relative to the client rectangle of the user control or form. The syntax of the ClipRectangle property is: Public ReadOnly Property ClipRectangle As System.Drawing.Rectangle Graphics Defines the graphics surface on which to draw. The syntax of the Graphics property is: Public ReadOnly Property Graphics As System.Drawing.Graphics The following list shows some of the Graphics classs many methods that are available for drawing various lines and shapes, and Ex am ple 5- 7 in Chapt er 5 gives an example of drawing a filled ellipse. This list is just to get you started; it is beyond the scope of this book to document the syntax of each of these methods. DrawArc Draws an arc that is, a portion of an ellipse. DrawBezier Draws a Bezier curve. DrawBeziers Draws a series of Bezier curves. DrawClosedCurve Is the same as the DrawCurve method see the next item in this list, except that the last point in the curve is connected back to the first point. DrawCurve 162 Draws a smooth, curved figure that passes through a given array of points. DrawEllipse Draws an ellipse. DrawIcon Draws an icon. Icons are represented by objects of type Icon defined in the System.Drawing namespace. The Icon class defines various methods for loading icons. DrawIconUnstretched Is the same as the DrawIcon method, but does not stretch the icon to fit the clipping rectangle. DrawImage Draws an image. Images are represented by objects of type Image defined in the System.Drawing namespace. The Image class defines various methods for loading images in standard formats, such as bitmaps and JPEGs. DrawImageUnscaled Is the same as DrawImage, except that the DrawImageUnscaled method ignores any width and height parameters passed to it. DrawLine Draws a line. DrawLines Draws a series of lines. DrawPath Draws a series of lines and curves that are defined by a GraphicsPath object. The GraphicsPath class is beyond the scope of this book. DrawPie Draws a pie section. DrawPolygon Draws lines to connect a series of points. DrawRectangle Draws a rectangle. DrawRectangles Draws a series of rectangles. 163 DrawString Draws text. FillClosedCurve Draws a filled, closed curve. FillEllipse Draws a filled ellipse. FillPath Draws a filled figure whose shape is given by a GraphicsPath object. The GraphicsPath class is beyond the scope of this book. FillPie Draws a filled pie section. FillPolygon Draws a filled polygon see the DrawPolygon method earlier in this list. FillRectangle Draws a filled rectangle. FillRectangles Draws a series of filled rectangles. FillRegion Draws a filled figure whose shape is given by a Region object.

4.6.2 The Pen Class