CanvasWrapper constructor.


CanvasWrapper(Canvas inCanvas);

[Visual Basic]

Sub New(inCanvas As Canvas)
Name Description
inCanvas The Canvas object to be wrapped.

This object will wrap a Canvas object in a System.Drawing Graphics context. Use Graphics to get access to the System.Drawing graphics context. Do not use the canvas until you have called Unwrap or have disposed of this object.



Canvas canvas = new Canvas(Server.MapPath("rez/sunset.jpg"));
canvas.DrawText("Hi there", new DrawOptions());
using (CanvasWrapper wrapper = new CanvasWrapper(canvas)) {
  Pen pn = new Pen(Color.DarkGoldenrod, 8);
  wrapper.Graphics.DrawEllipse(pn, 10, 25, 125, 125);
  pn.Color = Color.SteelBlue;
  wrapper.Graphics.DrawPie(pn, 10, 25, 125, 125, 45, 120);

[Visual Basic]

Dim canvas As New Canvas(Server.MapPath("rez/sunset.jpg"))
canvas.DrawText("Hi there", New DrawOptions())
Using wrapper As New CanvasWrapper(canvas)
  Dim pn As New Pen(Color.DarkGoldenrod, 8)
  wrapper.Graphics.DrawEllipse(pn, 10, 25, 125, 125)
  pn.Color = Color.SteelBlue
  wrapper.Graphics.DrawPie(pn, 10, 25, 125, 125, 45, 120)
End Using

The code above wraps a Canvas and uses the wrapper Graphics property to draw on the Canvas with GDI calls. Do not use the Canvas inside the using code block. The original and modified pictures are shown below.