Font.HorizontalAlignment Property

Gets or sets a horizontal text alignment.

Namespace: Aurigma.GraphicsMill.Drawing
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

C#
public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

A HorizontalAlignment value. The default value is Left.

Remarks

Horizontal text alignment is a value specifying how to locate the text string relatively to an X-coordinate of the output point (which is defined in the DrawString(String, Font, Pen, Brush, Int32, Int32) method).

Examples

C#
using (var bitmap = new Bitmap(100, 100, PixelFormat.Format24bppRgb, RgbColor.White))
{
    using (var graphics = bitmap.GetGraphics())
    {
        var pen = new Pen(RgbColor.Red, 1);
        graphics.DrawLine(pen, 50, 0, 50, 100);

        var brush = new SolidBrush(RgbColor.Black);

        //Adjust font settings
        var font = new Font("Arial", 20, false, false);

        //Draw text with different horizontal alignments        
        font.HorizontalAlignment = HorizontalAlignment.Left;
        graphics.DrawString("Left", font, brush, 50, 0);

        font.HorizontalAlignment = HorizontalAlignment.Center;
        graphics.DrawString("Center", font, brush, 50, 33);

        font.HorizontalAlignment = HorizontalAlignment.Right;
        graphics.DrawString("Right", font, brush, 50, 63);

        bitmap.Save(@"Images\Output\string.png");
    }
}

See Also

Reference