Type Default Value Read Only Static Description
Double 0 No No The object horizontal alignment.

Use this property to specify horizontal alignment for objects that do not have their position set explicitly via the Canvas drawing methods. This property is an offset from the left. You can specify a value ranging from zero to one:

  • 0 corresponds to left
  • 0.5 corresponds to middle
  • 1 corresponds to right.
See Also



Here we draw an image and a text caption on a Canvas. We centre horizontally text and image. The image is aligned to the top (the default) and the caption to the bottom.

[C#]Canvas canvas = new Canvas();
XImage image = XImage.FromFile(Server.MapPath("rez/boat.gif"));
DrawOptions drawOpts = new DrawOptions();
drawOpts.HAlign = 0.5;
drawOpts.VAlign = 0;
drawOpts.TextHAlign = 0.5;
drawOpts.TextVAlign = 1;
XText caption = canvas.GetTextMetrics("My image caption", drawOpts);
canvas.Width = image.Width + 40;
canvas.Height = image.Height + caption.LineHeight;
canvas.DrawImage(image, drawOpts);
canvas.DrawText(caption.Text, drawOpts);

[Visual Basic]Dim canvas As New Canvas()
Dim image As XImage = XImage.FromFile(Server.MapPath("rez/boat.gif"))
Dim drawOpts As New DrawOptions()
drawOpts.HAlign = 0.5
drawOpts.VAlign = 0
drawOpts.TextHAlign = 0.5
drawOpts.TextVAlign = 1
Dim caption As XText = canvas.GetTextMetrics("My image caption", drawOpts)
canvas.Width = image.Width + 40
canvas.Height = image.Height + caption.LineHeight
canvas.DrawImage(image, drawOpts)
canvas.DrawText(caption.Text, drawOpts)