In This Article

CanvasDrawContext Class

Provides access for drawing the content of an ICanvas.

public class CanvasDrawContext : DisposableObject, IDisposable
Inheritance:
Object MarshalByRefObject DisposableObject Object
Derived:
TextViewDrawContext
Implements:
IDisposable

Constructors

CanvasDrawContext(ICanvas, Graphics, Rectangle)

Initializes an instance of the CanvasDrawContext class.

public CanvasDrawContext(ICanvas canvas, Graphics platformRenderer, Rectangle bounds)
Parameter Type Description
canvas ICanvas

The ICanvas being drawn.

platformRenderer Graphics

The native object used for drawing.

bounds Rectangle

The bounds in which to draw.

Properties

Bounds

Gets the bounds in which to draw.

public Rectangle Bounds { get; }

Property Value

Rectangle:

The bounds in which to draw.

Canvas

Gets the ICanvas being drawn.

public ICanvas Canvas { get; }

Property Value

ICanvas:

The ICanvas being drawn.

ClipBounds

Gets the current clip bounds in which to draw.

public Rectangle ClipBounds { get; }

Property Value

Rectangle:

The current clip bounds in which to draw.

See Also

DpiScale

Gets the additional scale factor caused by the monitor DPI (WinForms only).

public float DpiScale { get; }

Property Value

Single:

The additional scale factor caused by the monitor DPI (WinForms only).

IsNativeRendering

Gets or sets whether native rendering is currently active.

public bool IsNativeRendering { get; set; }

Property Value

Boolean:

true if native rendering is currently active; otherwise, false.

PlatformRenderer

Gets the native object used for drawing.

public Graphics PlatformRenderer { get; }

Property Value

Graphics:

The native object used for drawing.

Scale

Gets the current scale factor.

public double Scale { get; }

Property Value

Double:

The current scale factor.

Methods

Dispose(Boolean)

Releases the unmanaged resources used by the object and optionally releases the managed resources.

protected override void Dispose(bool disposing)
Parameter Type Description
disposing Boolean

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

This method is called by the public Dispose method and the Finalize method. Dispose invokes this method with the disposing parameter set to true. Finalize invokes this method with disposing set to false.

DrawEllipse(Rectangle, Color, LineKind, Single)

Draws an ellipse shape.

public void DrawEllipse(Rectangle bounds, Color color, LineKind lineKind, float strokeWidth)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

color Color

The line color.

lineKind LineKind

A LineKind that indicates the line's dash style. A common default value is Solid.

strokeWidth Single

The stroke width. A common default value is 1.0.

DrawEllipse(Rectangle, Pen)

Draws an ellipse shape.

public void DrawEllipse(Rectangle bounds, Pen pen)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

pen Pen

The line pen.

DrawGeometry(Point, GraphicsPath, Color, LineKind, Single)

Draws a geometry.

public void DrawGeometry(Point location, GraphicsPath geometry, Color color, LineKind lineKind, float strokeWidth)
Parameter Type Description
location Point

The location at which to draw the geometry.

geometry GraphicsPath

The geometry.

color Color

The stroke color.

lineKind LineKind

A LineKind that indicates the line's dash style. A common default value is Solid.

strokeWidth Single

The stroke width. A common default value is 1.0.

DrawGeometry(Point, GraphicsPath, Pen)

Draws a geometry.

public void DrawGeometry(Point location, GraphicsPath geometry, Pen pen)
Parameter Type Description
location Point

The location at which to draw the geometry.

geometry GraphicsPath

The geometry.

pen Pen

The stroke pen.

DrawImage(Point, Image)

Draws an image.

public void DrawImage(Point location, Image imageSource)
Parameter Type Description
location Point

The location at which to draw the image.

imageSource Image

The image source.

DrawLine(Point, Point, Color, LineKind, Single)

Draws a line.

public void DrawLine(Point startLocation, Point endLocation, Color color, LineKind lineKind, float strokeWidth)
Parameter Type Description
startLocation Point

The start location of the line.

endLocation Point

The end location of the line.

color Color

The line color.

lineKind LineKind

A LineKind that indicates the line's dash style. A common default value is Solid.

strokeWidth Single

The stroke width. A common default value is 1.0.

DrawLine(Point, Point, Pen)

Draws a line.

public void DrawLine(Point startLocation, Point endLocation, Pen pen)
Parameter Type Description
startLocation Point

The start location of the line.

endLocation Point

The end location of the line.

pen Pen

The line pen.

DrawRectangle(Rectangle, Color, LineKind, Single)

Draws a rectangle shape.

public void DrawRectangle(Rectangle bounds, Color color, LineKind lineKind, float strokeWidth)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

color Color

The line color.

lineKind LineKind

A LineKind that indicates the line's dash style. A common default value is Solid.

strokeWidth Single

The stroke width. A common default value is 1.0.

DrawRectangle(Rectangle, Pen)

Draws a rectangle shape.

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

The bounds in which to draw.

pen Pen

The line color.

DrawRoundedRectangle(Rectangle, Single, Color, LineKind, Single)

Draws a rounded rectangle shape.

public void DrawRoundedRectangle(Rectangle bounds, float radius, Color color, LineKind lineKind, float strokeWidth)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

radius Single

The corner radius.

color Color

The line color.

lineKind LineKind

A LineKind that indicates the line's dash style. A common default value is Solid.

strokeWidth Single

The stroke width. A common default value is 1.0.

DrawRoundedRectangle(Rectangle, Single, Pen)

Draws a rounded rectangle shape.

public void DrawRoundedRectangle(Rectangle bounds, float radius, Pen pen)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

radius Single

The corner radius.

pen Pen

The line color.

DrawSquiggleLine(Rectangle, Color)

Draws a squiggle line.

public void DrawSquiggleLine(Rectangle bounds, Color color)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

color Color

The line color.

DrawText(Point, ITextLayoutLine)

Draws an ITextLayoutLine at the specified location.

public void DrawText(Point location, ITextLayoutLine line)
Parameter Type Description
location Point

The location at which to draw the text.

line ITextLayoutLine

The ITextLayoutLine to draw.

FillEllipse(Rectangle, Brush)

Fills an ellipse shape.

public void FillEllipse(Rectangle bounds, Brush brush)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

brush Brush

The fill brush.

FillEllipse(Rectangle, Color)

Fills an ellipse shape.

public void FillEllipse(Rectangle bounds, Color color)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

color Color

The fill color.

FillGeometry(Point, GraphicsPath, Brush)

Fills a geometry.

public void FillGeometry(Point location, GraphicsPath geometry, Brush brush)
Parameter Type Description
location Point

The location at which to draw the geometry.

geometry GraphicsPath

The geometry.

brush Brush

The fill brush.

FillGeometry(Point, GraphicsPath, Color)

Fills a geometry.

public void FillGeometry(Point location, GraphicsPath geometry, Color color)
Parameter Type Description
location Point

The location at which to draw the geometry.

geometry GraphicsPath

The geometry.

color Color

The fill color.

FillRectangle(Rectangle, Brush)

Fills a rectangle shape.

public void FillRectangle(Rectangle bounds, Brush brush)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

brush Brush

The fill brush.

FillRectangle(Rectangle, Color)

Fills a rectangle shape.

public void FillRectangle(Rectangle bounds, Color color)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

color Color

The fill color.

FillRoundedRectangle(Rectangle, Single, Brush)

Fills a rounded rectangle shape.

public void FillRoundedRectangle(Rectangle bounds, float radius, Brush brush)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

radius Single

The corner radius.

brush Brush

The fill brush.

FillRoundedRectangle(Rectangle, Single, Color)

Fills a rectangle shape.

public void FillRoundedRectangle(Rectangle bounds, float radius, Color color)
Parameter Type Description
bounds Rectangle

The bounds in which to draw.

radius Single

The corner radius.

color Color

The fill color.

PopBounds()

Pops a target Bounds.

public void PopBounds()

PopClip()

Pops a clip.

public void PopClip()

PushBounds(Rectangle)

Pushes a target Bounds.

public void PushBounds(Rectangle bounds)
Parameter Type Description
bounds Rectangle

The new target bounds.

PushClip(Rectangle)

Pushes a clip.

public void PushClip(Rectangle clipBounds)
Parameter Type Description
clipBounds Rectangle

The clip bounds.

Inherited Members