Graphics.DrawString Method (String, Font, SolidBrush, Int32, Int32)

Draws the specified text string at the specified location with the specified Font and SolidBrush settings.

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

Syntax

C#
public void DrawString(
	string string,
	Font font,
	SolidBrush brush,
	int x,
	int y
)

Parameters

string

Type: System.String

A string to draw.
font

Type: Aurigma.GraphicsMill.Drawing.Font

A Font that defines the text format of the string.
brush

Type: Aurigma.GraphicsMill.Drawing.SolidBrush

A SolidBrush that determines the color of the drawn text.
x

Type: System.Int32

The x-coordinate of the upper-left corner of the drawn text. Actual position of the text is defined with HorizontalAlignment and VerticalAlignment properties of the font argument.
y

Type: System.Int32

The y-coordinate of the upper-left corner of the drawn text. Actual position of the text relatively this point is defined with HorizontalAlignment and VerticalAlignment properties of the font argument.

Remarks

The extent of the text drawn by this method can be measured using the MeasureString(String, Font) method.

Note

When you try to draw text on a grayscale bitmap, you will notice that the text is not antialiased. The reason of this problem is that neither GDI nor GDI+ support grayscale bitmaps, therefore Graphics Mill has to imitate it as indexed bitmap with grayscale palette. However, antialiasing is impossible on indexed bitmaps.

Examples

C#
using (var bitmap = new Bitmap(300, 30, PixelFormat.Format24bppRgb, RgbColor.White))
{
    using (var graphics = bitmap.GetGraphics())
    {
        //Draw text
        var font = new Font("Futura Md BT", 20);
        font.Bold = false;
        font.Italic = true;
        font.Underline = true;
        font.Strikeout = false;
        font.HorizontalAlignment = HorizontalAlignment.Center;

        var brush = new SolidBrush(RgbColor.Red);

        graphics.DrawString("Sample text", font, brush, 150, 0);

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

See Also

Reference