In This Article

DrawingHelper Class

A helper class containing various drawing procedures.

public class DrawingHelper
Inheritance:
object object

Constructors

DrawingHelper()

Initializes an instance of the class.

public DrawingHelper()

Properties

DesktopGraphics

Gets the Graphics associated with the Windows desktop.

public static Graphics DesktopGraphics { get; }

Property Value

Graphics:

A Graphics object.

Remarks

DO NOT dispose if the Graphics returned by this property.

Methods

CreateTemporaryGraphicsState(Graphics)

Creates an object that automatically saves the current GraphicsState which is later restored when the object is disposed.

public static IDisposable CreateTemporaryGraphicsState(Graphics g)
Parameter Type Description
g Graphics

The Graphics object to manage.

Returns

IDisposable:

An IDisposable which must be disposed to restore the state.

CreateXamlImage(string, Size, Size)

Creates a new Image from a XAML DrawingImage for supported geometries.

public static Image CreateXamlImage(string xaml, Size xamlSize, Size imageSize)
Parameter Type Description
xaml string

The XAML which defines the DrawingImage.

xamlSize Size

The size of the XAML DrawingImage.

imageSize Size

The size of the target Image. XAML images will scale to match fit the image.

Returns

Image

Remarks

For internal use only.

CreateXamlImage(string, Size, Size, RotateFlipType)

Creates a new Image from a XAML DrawingImage for supported geometries.

public static Image CreateXamlImage(string xaml, Size xamlSize, Size imageSize, RotateFlipType imageRotation)
Parameter Type Description
xaml string

The XAML which defines the DrawingImage.

xamlSize Size

The size of the XAML DrawingImage.

imageSize Size

The size of the target Image before any optional rotation is applied. XAML images will scale to match fit the image.

imageRotation RotateFlipType

The image rotation.

Returns

Image

Remarks

For internal use only.

DrawImage(Graphics, Image, int, int, int, int, float, RotateFlipType)

Draws an image.

public static void DrawImage(Graphics g, Image image, int x, int y, int width, int height, float alpha, RotateFlipType imageRotation)
Parameter Type Description
g Graphics

The Graphics object used to paint.

image Image

The Image to draw.

x int

The x-coordinate at which to draw.

y int

The y-coordinate at which to draw.

width int

The width of the image.

height int

The height of the image.

alpha float

The opacity of the image (decimal between 0 and 1).

imageRotation RotateFlipType

The image rotation.

DrawImage(Graphics, Image, int, int, float, RotateFlipType)

Draws an image.

public static void DrawImage(Graphics g, Image image, int x, int y, float alpha, RotateFlipType imageRotation)
Parameter Type Description
g Graphics

The Graphics object used to paint.

image Image

The Image to draw.

x int

The x-coordinate at which to draw.

y int

The y-coordinate at which to draw.

alpha float

The opacity of the image (decimal between 0 and 1).

imageRotation RotateFlipType

The image rotation.

DrawImageShadow(Graphics, Image, int, int, int, int, float, RotateFlipType)

Draws an image shadow.

public static void DrawImageShadow(Graphics g, Image image, int x, int y, int width, int height, float alpha, RotateFlipType imageRotation)
Parameter Type Description
g Graphics

The Graphics object used to paint.

image Image

The Image to use for creating the shadow.

x int

The x-coordinate at which to draw.

y int

The y-coordinate at which to draw.

width int

The width of the image.

height int

The height of the image.

alpha float

The opacity of the image (decimal between 0 and 1).

imageRotation RotateFlipType

The image rotation.

DrawImageShadow(Graphics, Image, int, int, float, RotateFlipType)

Draws an image shadow.

public static void DrawImageShadow(Graphics g, Image image, int x, int y, float alpha, RotateFlipType imageRotation)
Parameter Type Description
g Graphics

The Graphics object used to paint.

image Image

The Image to use for creating the shadow.

x int

The x-coordinate at which to draw.

y int

The y-coordinate at which to draw.

alpha float

The opacity of the image (decimal between 0 and 1).

imageRotation RotateFlipType

The image rotation.

DrawRectangle(Graphics, Rectangle, Color, DashStyle)

Draws a rectangle with the specified color and dash style.

public static void DrawRectangle(Graphics g, Rectangle bounds, Color color, DashStyle dashStyle)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds Rectangle

The bounds of the area.

color Color

The Color to use for drawing.

dashStyle DashStyle

The DashStyle to use for drawing.

Remarks

The bounds are automatically adjusted for optimal rendering.

DrawRectangle(Graphics, Rectangle, Pen)

Draws a rectangle.

public static void DrawRectangle(Graphics g, Rectangle bounds, Pen pen)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds Rectangle

The bounds of the area.

pen Pen

The Pen to use for drawing.

Remarks

The bounds are automatically adjusted for optimal rendering.

DrawRoundedRectangle(Graphics, Rectangle, int, int, Pen)

Draws a rounded rectangle.

public static void DrawRoundedRectangle(Graphics g, Rectangle bounds, int radiusX, int radiusY, Pen pen)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds Rectangle

The bounds of the area.

radiusX int

The radius of the corner on the x-axis. This value will be clamped to the range of 0 to half the width.

radiusY int

The radius of the corner on the y-axis. This value will be clamped to the range of 0 to half the height.

pen Pen

The Pen to use for drawing.

Remarks

The bounds and Graphics are automatically adjusted for optimal rendering.

DrawRoundedRectangle(Graphics, RectangleF, float, float, Pen)

Draws a rounded rectangle.

public static void DrawRoundedRectangle(Graphics g, RectangleF bounds, float radiusX, float radiusY, Pen pen)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds RectangleF

The bounds of the area.

radiusX float

The radius of the corner on the x-axis. This value will be clamped to the range of 0 to half the width.

radiusY float

The radius of the corner on the y-axis. This value will be clamped to the range of 0 to half the height.

pen Pen

The Pen to use for drawing.

Remarks

The bounds and Graphics are automatically adjusted for optimal rendering.

DrawString(Graphics, string, Font, Color, RectangleF, StringFormat)

Draws a string.

public static void DrawString(Graphics g, string text, Font font, Color color, RectangleF bounds, StringFormat format)
Parameter Type Description
g Graphics

The Graphics object to use.

text string

The text to draw.

font Font

The Font to use when drawing the text.

color Color

The Color to use when drawing the text.

bounds RectangleF

The bounds in which to draw the text.

format StringFormat

The StringFormat to use when drawing the text.

DrawWrappedImage(Graphics, Rectangle, Rectangle, Image, WrapMode)

Draws a wrapped Image.

public static void DrawWrappedImage(Graphics g, Rectangle bounds, Rectangle brushBounds, Image image, WrapMode wrapMode)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds Rectangle

A Rectangle indicating the bounds of the drawing operation.

brushBounds Rectangle

The reference bounds for the brush.

image Image

The Image to draw.

wrapMode WrapMode

The WrapMode to tile with.

DrawXaml(Graphics, string, int, int)

Draws a XAML DrawingImage for supported geometries.

public static void DrawXaml(Graphics g, string xaml, int x, int y)
Parameter Type Description
g Graphics

The Graphics object to use.

xaml string

The XAML which defines the DrawingImage.

x int

The x-coordinate of the upper-left corner where the drawing will be anchored.

y int

The y-coordinate of the upper-left corner where the drawing will be anchored.

Remarks

For internal use only.

DrawXaml(Graphics, string, int, int, SizeF)

Draws a XAML DrawingImage for supported geometries.

public static void DrawXaml(Graphics g, string xaml, int x, int y, SizeF scaleFactor)
Parameter Type Description
g Graphics

The Graphics object to use.

xaml string

The XAML which defines the DrawingImage.

x int

The x-coordinate of the upper-left corner where the drawing will be anchored.

y int

The y-coordinate of the upper-left corner where the drawing will be anchored.

scaleFactor SizeF

A scale factor to apply to the original image when drawn.

Remarks

For internal use only.

FillRoundedRectangle(Graphics, Rectangle, int, int, Brush)

Fills a rounded rectangle.

public static void FillRoundedRectangle(Graphics g, Rectangle bounds, int radiusX, int radiusY, Brush brush)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds Rectangle

The bounds of the area.

radiusX int

The radius of the corner on the x-axis. This value will be clamped to the range of 0 to half the width.

radiusY int

The radius of the corner on the y-axis. This value will be clamped to the range of 0 to half the height.

brush Brush

The Brush to use for drawing.

FillRoundedRectangle(Graphics, RectangleF, float, float, Brush)

Fills a rounded rectangle.

public static void FillRoundedRectangle(Graphics g, RectangleF bounds, float radiusX, float radiusY, Brush brush)
Parameter Type Description
g Graphics

The Graphics object used to paint.

bounds RectangleF

The bounds of the area.

radiusX float

The radius of the corner on the x-axis. This value will be clamped to the range of 0 to half the width.

radiusY float

The radius of the corner on the y-axis. This value will be clamped to the range of 0 to half the height.

brush Brush

The Brush to use for drawing.

GetCenteredRectangleLocation(Rectangle, Size)

Gets the Point at which the specified rectangle should be located within the bounds to be centered.

public static Point GetCenteredRectangleLocation(Rectangle bounds, Size size)
Parameter Type Description
bounds Rectangle

The bounds of the parent.

size Size

The child rectangle's size.

Returns

Point:

A Point specifying the upper-left position that the rectangle should be placed.

GetDarkBorderColor(Color)

Gets the color to be used for a Dark border.

public static Color GetDarkBorderColor(Color baseBorderColor)
Parameter Type Description
baseBorderColor Color

The base border color.

Returns

Color:

the Dark color.

GetDarkDarkBorderColor(Color)

Gets the color to be used for a DarkDark border.

public static Color GetDarkDarkBorderColor(Color baseBorderColor)
Parameter Type Description
baseBorderColor Color

The base border color.

Returns

Color:

the DarkDark color.

GetHatchedBrush(Color, Color)

Creates a hatched checkerboard brush.

public static TextureBrush GetHatchedBrush(Color color1, Color color2)
Parameter Type Description
color1 Color

The first color to use.

color2 Color

The second color to use.

Returns

TextureBrush:

A TextureBrush that is a checkerboard-patterned brush.

GetHatchedBrush(Color, Color, SizeF)

Creates a hatched checkerboard brush.

public static TextureBrush GetHatchedBrush(Color color1, Color color2, SizeF scaleFactor)
Parameter Type Description
color1 Color

The first color to use.

color2 Color

The second color to use.

scaleFactor SizeF

The factor of the scale transform to be applied where Width is applied to the x-axis, and Height is applied to the y-axis.

Returns

TextureBrush:

A TextureBrush that is a checkerboard-patterned brush.

GetLightBorderColor(Color)

Gets the color to be used for a Light border.

public static Color GetLightBorderColor(Color baseBorderColor)
Parameter Type Description
baseBorderColor Color

The base border color.

Returns

Color:

the Light color.

GetLightLightBorderColor(Color)

Gets the color to be used for a LightLight border.

public static Color GetLightLightBorderColor(Color baseBorderColor)
Parameter Type Description
baseBorderColor Color

The base border color.

Returns

Color:

the LightLight color.

GetOppositeSides(Sides)

Returns a Sides value containing the sides that are not specified.

public static Sides GetOppositeSides(Sides sides)
Parameter Type Description
sides Sides

The Sides value whose opposite sides are to be found.

Returns

Sides:

A Sides value containing the sides that are not specified.

GetShortcutTextFromShortcut(Shortcut)

Gets the proper display text of a shortcut.

public static string GetShortcutTextFromShortcut(Shortcut shortcut)
Parameter Type Description
shortcut Shortcut

The Shortcut whose text is to be retrieved.

Returns

string:

The proper display text of a shortcut.

GetStringFormat(StringAlignment, StringAlignment, StringTrimming, bool, bool)

Gets a StringFormat for the specified parameters.

public static StringFormat GetStringFormat(StringAlignment hAlign, StringAlignment vAlign, StringTrimming trimming, bool wrap, bool vertical)
Parameter Type Description
hAlign StringAlignment

A StringAlignment indicating the horizontal alignment.

vAlign StringAlignment

A StringAlignment indicating the vertical alignment.

trimming StringTrimming

A StringTrimming indicating the trimming method.

wrap bool

Whether to allow wrapped text.

vertical bool

Whether to work with vertical text.

Returns

StringFormat:

A StringFormat for the specified parameters.

MeasureString(Graphics, string, Font, StringFormat)

Measures a string.

public static Size MeasureString(Graphics g, string text, Font font, StringFormat format)
Parameter Type Description
g Graphics

The Graphics object to use.

text string

The text to draw.

font Font

The Font to use when drawing the text.

format StringFormat

The StringFormat to use when drawing the text.

Returns

Size

ParseXamlGeometry(string)

Parses a GraphicsPath from a supported XAML geometry.

public static GraphicsPath ParseXamlGeometry(string geometry)
Parameter Type Description
geometry string

The XAML geometry.

Returns

GraphicsPath:

A GraphicsPath.

Remarks

For internal use only.

ResolveFirstNonEmptyColor(params Color[])

Returns the first color that is not empty.

public static Color ResolveFirstNonEmptyColor(params Color[] colors)
Parameter Type Description
colors Color[]

The colors to be examined in order of preference.

Returns

Color:

The first non-empty color, or Empty if a non-empty color could not be found.

Fields

UnscaledFactor

Gets a scale factor which indicates no scaling should occur.

public static readonly SizeF UnscaledFactor

Inherited Members