Drawing Classes


The following sections describe the most useful properties and methods provided by key drawing classes.

Graphics

The Graphics object represents a drawing surface. It provides many methods for drawing shapes, filling areas, and determining the appearance of drawing results. All of these methods except DrawString take a Pen object as a parameter to determine the lines’ color, thickness, dash style, and other properties. DrawString takes a Brush object instead of a Pen object as a parameter.

The following table lists the Graphics object’s drawing methods.

Open table as spreadsheet

Drawing Method

Purpose

DrawArc

Draws an arc of an ellipse.

DrawBezier

Draws a Bézier curve.

DrawBeziers

Draws a series of connected Bézier curves.

DrawClosedCurve

Draws a closed curve that connects a series of points, joining the final point to the first point.

DrawCurve

Draws a smooth curve that connects a series of points.

DrawEllipse

Draws an ellipse.

DrawIcon

Draws an Icon onto the Graphics object’s drawing surface.

DrawIconUnstretched

Draws an Icon object onto the Graphics object’s drawing surface without scaling.

DrawImage

Draws an Image object onto the Graphics object’s drawing surface.

DrawImageUnscaled

Draws an Image object onto the drawing surface without scaling.

DrawLine

Draws a line.

DrawLines

Draws a series of connected lines.

DrawPath

Draws a GraphicsPath object.

DrawPie

Draws a pie slice taken from an ellipse.

DrawPolygon

Draws a polygon.

DrawRectangle

Draws a rectangle.

DrawRectangles

Draws a series of rectangles.

DrawString

Draws text on the drawing surface.

The following table lists the Graphics object’s area filling methods. These methods take Brush objects as parameters to determine the filled shape’s color, hatch pattern, gradient colors, and other fill characteristics.

Open table as spreadsheet

Filling Method

Purpose

FillClosedCurve

Fills a smooth curve that connects a series of points.

FillEllipse

Fills an ellipse.

FillPath

Fills a GraphicsPath object.

FillPie

Fills a pie slice taken from an ellipse.

FillPolygon

Fills a polygon.

FillRectangle

Fills a rectangle.

FillRectangles

Fills a series of rectangles.

FillRegion

Fills a Region object.

The following table lists other useful Graphics object properties and methods.

Open table as spreadsheet

Properties and Methods

Purpose

AddMetafileComment

Adds a comment to a metafile.

Clear

Clears the Graphics object and fills it with a specific color.

Clip

Determines the Region object used to clip drawing on the Graphics surface.

Dispose

Releases the resources held by the Graphics object.

DpiX

Returns the horizontal number of dots per inch (DPI) for this object’s surface.

DpiY

Returns the vertical number of dots per inch (DPI) for this object’s surface.

ExcludeClip

Updates the Graphics object’s clipping region to exclude the area defined by a Region or Rectangle.

FromHdc

Creates a new Graphics object from a device context handle (hDC).

FromHwnd

Creates a new Graphics object from a window handle (hWnd).

FromImage

Creates a new Graphics object from an Image object.

InterpolationMode

Controls anti-aliasing when drawing images.

IntersectClip

Updates the Graphics object’s clipping region to be the intersection of the current clipping region and the area defined by a Region or Rectangle.

IsVisible

Returns True if a specified point is within the Graphics object’s visible clipping region.

MeasureCharacterRanges

Returns an array of Region objects that show where each character in a string will be drawn.

MeasureString

Returns a SizeF structure that gives the size of a string drawn on the Graphics object with a particular font.

MultiplyTransform

Multiplies the Graphics object’s current transformation matrix by another transformation matrix.

PageScale

Determines the amount by which drawing commands are scaled.

PageUnit

Determines the units of measurement: Display (depends on the device, typically pixel for monitors and 1/100 inch for printers), Document (1/300 inch), Inch, Millimeter, Pixel, or Point (1/72 inch).

RenderingOrigin

Determines the point used as a reference when hatching.

ResetClip

Resets the object’s clipping region so that the drawing is not clipped.

ResetTransformation

Resets the object’s transformation matrix to the identity matrix.

Restore

Restores the Graphics object to a state saved by the Save method.

RotateTransform

Adds a rotation to the object’s current transformation.

Save

Saves the object’s current state.

ScaleTransform

Adds a scaling transformation to the Graphics object’s current transformation.

SetClip

Sets or merges the Graphics object’s clipping area to another Graphics object, a GraphicsPath object, or a Rectangle.

SmoothingMode

Controls anti-aliasing when drawing lines, curves, or filled areas.

TextRenderingHint

Controls anti-aliasing and hinting when drawing text.

Transform

Gets or sets the Graphics object’s transformation matrix.

TransformPoints

Applies the object’s current transformation to an array of points.

TranslateTransform

Adds a translation transformation to the Graphics object’s current transformation.

Pen

The Pen object determines the appearance of drawn lines. It determines such properties as a line’s width, color, and dash style. The following table lists the Pen object’s most useful properties and methods.

Open table as spreadsheet

Properties and Methods

Purpose

Alignment

Determines whether the line is drawn inside or centered on the theoretical perfectly thin line specified by the drawing routine.

Brush

Determines the Brush used to fill lines.

Color

Determines the lines’ color.

CompoundArray

Lets you draw lines that are striped lengthwise.

CustomEndCap

Determines the line’s end cap.

CustomStartCap

Determines the line’s start cap.

DashCap

Determines the cap drawn at the ends of dashes.

DashOffset

Determines the distance from the start of the line to the start of the first dash.

DashPattern

An array of Singles that specifies a custom dash pattern.

DashStyle

Determines the line’s dash style.

EndCap

Determines the cap used at the end of the line.

LineJoin

Determines how lines are joined by a GDI method that draws connected lines.

MultiplyTransform

Multiplies the Pen object’s current transformation by another transformation matrix.

ResetTransform

Resets the Pen object’s transformation to the identity transformation.

RotateTransform

Adds a rotation transformation to the Pen object’s current transformation.

ScaleTransform

Adds a scaling transformation to the Pen object’s current transformation.

SetLineCap

This method takes parameters that let you specify the Pen object’s StartCap, EndCap, and LineJoin properties at the same time.

StartCap

Determines the cap used at the start of the line.

Transform

Determines the transformation applied to the initially circular “pen tip” used to draw lines.

Width

The width of the pen.

Brushes

The Brush class is an abstract class, so you cannot make instances of it. Instead, you must make instances of one of its derived classes: SolidBrush, TextureBrush, HatchBrush, LinearGradientBrush, or PathGradientBrush. The following table briefly describes these classes.

Open table as spreadsheet

Class

Purpose

SolidBrush

Fills areas with a single solid color.

TextureBrush

Fills areas with a repeating image.

HatchBrush

Fills areas with a repeating hatch pattern.

LinearGradientBrush

Fills areas with a linear gradient of two or more colors.

PathGradientBrush

Fills areas with a color gradient that follows a path.

GraphicsPath

The GraphicsPath object represents a path defined by lines, curves, text, and other drawing commands. You can use Graphics object methods to fill and draw a GraphicsPath, and you can use a GraphicsPath to define a clipping region. The following table lists the GraphicsPath object’s most useful properties and methods.

Open table as spreadsheet

Properties and Methods

Purpose

CloseAllFigures

Closes all open figures by connecting their last points with their first points and then starts a new figure.

CloseFigure

Closes the current figure by connecting its last point with its first point and then starts a new figure.

FillMode

Determines how the path handles overlaps when you fill it. This property can take the values Alternate and Winding.

Flatten

Converts any curves in the path into a sequence of lines.

GetBounds

Returns a RectangleF structure representing the path’s bounding box.

GetLastPoint

Returns the last PointF structure in the PathPoints array.

IsOutlineVisible

Returns True if the indicated point lies beneath the path’s outline.

IsVisible

Returns True if the indicated point lies in the path’s interior.

PathData

Returns a PathData object that encapsulates the path’s graphical data.

PathPoints

Returns an array of PointF structures giving the points in the path.

PathTypes

Returns an array of Bytes representing the types of the points in the path.

PointCount

Returns the number of points in the path.

Reset

Clears the path data and resets FillMode to Alternate.

Reverse

Reverses the order of the path’s data.

StartFigure

Starts a new figure, so future data is added to the new figure.

Transform

Applies a transformation matrix to the path.

Warp

Applies a warping transformation defined by mapping a parallelogram onto a rectangle to the path.

Widen

Enlarges the curves in the path to enclose a line drawn by a specific pen.

StringFormat

The StringFormat object determines how text is formatted. It enables you to draw text that is centered vertically or horizontally, aligned on the left or right, and wrapped or truncated. The following table lists the StringFormat object’s most useful properties and methods.

Open table as spreadsheet

Properties and Methods

Purpose

Alignment

Determines the text’s horizontal alignment. This can be Near (left), Center (middle), or Far (right).

FormatFlags

Gets or sets flags that modify the StringFormat object’s behavior.

GetTabStops

Returns an array of Singles giving the positions of tab stops.

HotkeyPrefix

Determines how the hotkey prefix character is displayed. This can be Show, Hide, or None.

LineAlignment

Determines the text’s vertical alignment. This can be Near (top), Center (middle), or Far (bottom).

SetMeasureableCharacter?Ranges

Sets an array of CharacterRange structures representing ranges of characters that will later be measured by the Graphics object’s MeasureCharacterRanges method.

SetTabStops

Sets an array of Singles giving the positions of tab stops.

Trimming

Determines how the text is trimmed if it cannot fit within the layout rectangle.

Image

The Image class represents the underlying physical drawing surface hidden below the logical layer created by the Graphics class. Image is an abstract class, so you cannot directly create instances of it. Instead, you must create instances of its child classes Bitmap and Metafile.

The following table describes the Image class’s most useful properties and methods, which are inherited by the Bitmap and Metafile classes.

Open table as spreadsheet

Properties and Methods

Purpose

Dispose

Frees the resources associated with this image.

Flags

Returns attribute flags for the image.

FromFile

Loads an image from a file.

FromHbitmap

Loads a Bitmap image from a Windows bitmap handle.

FromStream

Loads an image from a data stream.

GetBounds

Returns a RectangleF structure representing the rectangle’s bounds.

GetPixelFormatSize

Returns the color resolution (bits per pixel) for a specified PixelFormat.

GetThumbnailImage

Returns a thumbnail representation of the image.

Height

Returns the image’s height.

HorizontalResolution

Returns the horizontal resolution of the image in pixels per inch.

IsAlphaPixelFormat

Returns True if the specified PixelFormat contains alpha information.

Palette

Determines the ColorPalette object used by the image.

PhysicalDimension

Returns a SizeF structure giving the image’s dimensions in pixels for Bitmaps and 0.01 millimeters for Metafile classes.

PixelFormat

Returns the image’s pixel format.

RawFormat

Returns an ImageFormat object representing the image’s raw format.

RotateFlip

Rotates, flips, or rotates and flips the image.

Save

Saves the image in a file or stream with a given data format.

Size

Returns a Size structure containing the image’s width and height in pixels.

VerticalResolution

Returns the vertical resolution of the image in pixels per inch.

Width

Returns the image’s width.

Bitmap

The Bitmap class represents an image defined by pixel data. It inherits the Image class’s properties and methods described in the previous section. The following table describes some of the most useful new properties and methods added by the Bitmap class.

Open table as spreadsheet

Method

Purpose

FromHicon

Loads a Bitmap image from a Windows icon handle.

FromResource

Loads a Bitmap image from a Windows resource.

GetPixel

Returns a Color representing a specified pixel.

LockBits

Locks the Bitmap image’s data in memory, so it cannot move until the program calls UnlockBits.

MakeTransparent

Makes all pixels with a specified color transparent by setting the alpha component of those pixels to 0.

SetPixel

Sets a specified pixel’s Color value.

SetResolution

Sets the Bitmap image’s horizontal and vertical resolution in DPI.

UnlockBits

Unlocks the Bitmap image’s data in memory so that the system can relocate it, if necessary.

Metafile

The Metafile class represents an image defined by metafile records. It inherits the Image class’s properties and methods described in the section “Image” earlier in this appendix. The following table describes some of the most useful new properties and methods added by the Metafile class.

Open table as spreadsheet

Method

Purpose

GetMetafileHeader

Returns the MetafileHeader object associated with this Metafile.

PlayRecord

Plays a metafile record.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net