Draw a rectangle on the Canvas.
Syntax

[C#]

XRect DrawRect(double inWidth, double inHeight, DrawOptions inOptions);
XRect DrawRect(XRect inRect, DrawOptions inOptions);

[Visual Basic]

Function DrawRect(inWidth As Double, inHeight As Double, inOptions As DrawOptions) As XRect
Function DrawRect(inRect As XRect, inOptions As DrawOptions) As XRect
Params
Name Description
inWidth The rectangle width.
inHeight The rectangle height.
inOptions The draw options.
inRect The rectangle to draw.
return The drawn area.
Notes

Draw the specified rectangle on the Canvas using the properties specified in DrawOptions. If only the size is specified, the rectangle will be positioned using the align properties in DrawOptions.

See Also

DrawOptions

HAlign

VAlign

Example

Here we paint a blue rectangle on the Canvas, which is auto sized.

Note that the Canvas size is set to 250x250 because we center the image (25 + 200 + 25 = 250). Size the Canvas manually if this is not what you want.

[C#]Canvas canvas = new Canvas();
DrawOptions drawOpts = new DrawOptions();
drawOpts.ShapeDrawing = DrawOptions.ShapeDrawingType.Paint;
drawOpts.PaintColor = new XColor(Color.Blue);
canvas.DrawRect(new XRect(25, 25, 200, 200), drawOpts);
canvas.SaveAs(Server.MapPath("Canvas_DrawRect_92.png"));


[Visual Basic]Dim canvas As New Canvas()
Dim drawOpts As New DrawOptions()
drawOpts.ShapeDrawing = DrawOptions.ShapeDrawingType.Paint
drawOpts.PaintColor = New XColor(Color.Blue)
canvas.DrawRect(New XRect(25, 25, 200, 200), drawOpts)
canvas.SaveAs(Server.MapPath("Canvas_DrawRect_92.png"))



Canvas_DrawRect_92.png