Draws a string of text.
Syntax

[C#]

void DrawString(string text, Font font, Brush brush, double x, double y);
void DrawString(string text, Font font, Brush brush, double x, double y, stringFormat format);
void DrawString(string text, Font font, Brush brush, Pen pen, double x, double y, stringFormat format);
void DrawString(string text, Font font, Brush brush, Pen pen, PointF pt, stringFormat format);
void DrawString(string text, Font font, Brush brush, Pen pen, RectangleF rect, stringFormat format);
void DrawString(string text, Font font, Brush brush, PointF pt, stringFormat format);
void DrawString(string text, Font font, Brush brush, RectangleF rect, stringFormat format);

[Visual Basic]

Sub DrawString(text As String, font As Font, brush As Brush, x As Double, y As Double)
Sub DrawString(text As String, font As Font, brush As Brush, x As Double, y As Double, format As StringFormat)
Sub DrawString(text As String, font As Font, brush As Brush, pen As Pen, x As Double, y As Double, format As StringFormat)
Sub DrawString(text As String, font As Font, brush As Brush, pen As Pen, pt As PointF, format As StringFormat)
Sub DrawString(text As String, font As Font, brush As Brush, pen As Pen, rect As RectangleF, format As StringFormat)
Sub DrawString(text As String, font As Font, brush As Brush, pt As PointF, format As StringFormat)
Sub DrawString(text As String, font As Font, brush As Brush, rect As RectangleF, format As StringFormat)
Params
Name Description
text The text that should be drawn.
font The font to use.
brush The brush used to paint the text.
x The x position of the top left of the text.
y The y position of the top left of the text.
format The style and formatting for the text.
pen The pen to use for drawing the outlines of the text.
pt The top left for the text.
rect A rectangle in which the text should be positioned.
Notes

None.

Example

Here we use Language and TextFont to mix standard text and symbol fonts.

[C#]using (Bitmap bm = new Bitmap(600, 600)) {
  using (Graphics graphics = Graphics.FromImage(bm)) {
    graphics.Clear(Color.Yellow);
    Font font1 = new Font("Times", 48, FontStyle.Regular);
    Font font2 = new Font("Wingdings", 48, FontStyle.Regular);
    graphics.DrawString("Some text...", font1, Brushes.Black, new PointF(0, 0), StringFormat.GenericDefault);
    graphics.DrawString("Symbols.", font2, Brushes.Black, new PointF(0, 120), StringFormat.GenericDefault);
    graphics.DrawString("Some more text...", font1, Brushes.Black, new PointF(0, 240), StringFormat.GenericDefault);
  }
  bm.Save(Server.MapPath("IG8_Graphics_DrawString.png"));
}


It produces the following output image:


IG8_Graphics_DrawString.png