---
title: "Drawing Text String"
canonical: https://www.graphicsmill.com/docs/gm5/DrawingTextString.htm
product: "Graphics Mill 5.5 for .NET"
---

This documentation is for the old version. [Go to the latest Graphics Mill docs](https://www.graphicsmill.com/docs/gm/)

# Drawing Text String
 
To draw single-line text, Graphics Mill for .NET provides method [DrawString](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawString.htm.md) of the [GdiGraphics](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_GdiGraphics.htm.md) class. The following should be passed into this method:
 
- A text string to draw;
- A [Font](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_Font.htm.md) class instance initialized by proper font settings (size, name, etc);
- Coordinates of the text;
- A solid brush that specifies text color.

Some overloads of this method requires additional parameters to provide more features like [outlined text drawing](https://www.graphicsmill.com/docs/gm5/DrawingTextwithOutline.htm.md).
 
Let's examine a simple code example which draws the following text:
 ![Text sample.](https://www.graphicsmill.com/docs/gm5/DrawText1.png) 
Here is a code sample:
 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 300, 30, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics

'Draw text
Dim font As New Aurigma.GraphicsMill.Drawing.Font("Futura Md BT", 20)
font.Bold = False
font.Italic = True
font.Underline = True
font.Strikeout = False
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center

Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush( _
 Aurigma.GraphicsMill.RgbColor.Red)

graphics.DrawString("Sample text", font, brush, 150, 0)
```
 
```csharp
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 300, 30, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

//Draw text
Aurigma.GraphicsMill.Drawing.Font font = 
    new Aurigma.GraphicsMill.Drawing.Font("Futura Md BT", 20);
font.Bold = false;
font.Italic = true;
font.Underline = true;
font.Strikeout = false;
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center;

Aurigma.GraphicsMill.Drawing.SolidBrush brush = 
    new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Red);

graphics.DrawString("Sample text", font, brush, 150, 0);
```
 
Coordinates of the text can be treated in different ways. The interpretation of these coordinates depend on the text alignment (horizontal and vertical). Horizontal alignment can be modified with [HorizontalAlignment](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_Drawing_Font_HorizontalAlignment.htm.md) property of the Font class. It specifies whether X coordinate is a beginning (left position), center, or end (right position) of the text:
 ![Horizontal text alignment](https://www.graphicsmill.com/docs/gm5/DrawText2.png) 
This figure was produced with the following code:
 
```
'Create Bitmap object
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 100, 100, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics

Dim pen As New Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Red, 1)

graphics.DrawLine(pen, 50, 0, 50, 100)

Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush( _
 Aurigma.GraphicsMill.RgbColor.Black)

' Adjust font settings
Dim font As New Aurigma.GraphicsMill.Drawing.Font("Arial", 20, False, False)

'Draw text with different horizontal alignments        
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Left
graphics.DrawString("Left", font, brush, 50, 0)

font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center
graphics.DrawString("Center", font, brush, 50, 33)

font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Right
graphics.DrawString("Right", font, brush, 50, 63)
```
 
```csharp
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 100, 100, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

Aurigma.GraphicsMill.Drawing.Pen pen = new Aurigma.GraphicsMill.Drawing.Pen(
    Aurigma.GraphicsMill.RgbColor.Red, 1);

graphics.DrawLine(pen, 50, 0, 50, 100);

Aurigma.GraphicsMill.Drawing.SolidBrush brush = 
    new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

//Adjust font settings
Aurigma.GraphicsMill.Drawing.Font font = 
    new Aurigma.GraphicsMill.Drawing.Font("Arial", 20, false, false);

//Draw text with different horizontal alignments        
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Left;
graphics.DrawString("Left", font, brush, 50, 0);

font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center;
graphics.DrawString("Center", font, brush, 50, 33);

font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Right;
graphics.DrawString("Right", font, brush, 50, 63);
```
 
Vertical alignment can be modified with [VerticalAlignment](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_Drawing_Font_VerticalAlignment.htm.md) property of the Font class. It specifies whether Y coordinate specifies top, bottom or baseline level of the text:
 ![Vertical text alignment](https://www.graphicsmill.com/docs/gm5/DrawText3.png) 
This figure was created with the following code:
 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 200, 60, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics

Dim pen As New Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Red, 1)

graphics.DrawLine(pen, 0, 30, 200, 30)

Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black)

' Adjust font settings
Dim font As New Aurigma.GraphicsMill.Drawing.Font("Arial", 20, False, False)
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Left

'Draw text with different vertical alignments            
font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Bottom
graphics.DrawString("Bottom", font, brush, 0, 30)

font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Baseline
graphics.DrawString("Baseline", font, brush, 80, 30)

font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Top
graphics.DrawString("Top", font, brush, 160, 30)
```
 
```csharp
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 200, 60, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

Aurigma.GraphicsMill.Drawing.Pen pen = 
    new Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Red, 1);

graphics.DrawLine(pen, 0, 30, 200, 30);

Aurigma.GraphicsMill.Drawing.SolidBrush brush = 
    new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

//Adjust font settings
Aurigma.GraphicsMill.Drawing.Font font = 
    new Aurigma.GraphicsMill.Drawing.Font("Arial", 20, false, false);
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Left;

//Draw text with different vertical alignments            
font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Bottom;
graphics.DrawString("Bottom", font, brush, 0, 30);

font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Baseline;
graphics.DrawString("Baseline", font, brush, 80, 30);

font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Top;
graphics.DrawString("Top", font, brush, 160, 30);
```
 
To draw rotated text, like this:
 ![Rotated text sample.](https://www.graphicsmill.com/docs/gm5/DrawText4.png) 
you should set rotation matrix into [Transform](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_Drawing_GdiGraphics_Transform.htm.md) property of the GdiGraphics before drawing the text:
 
```
'Create Bitmap object
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 120, 120, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics

Dim pen As New Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Black, 1)

Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black)

'Adjust font settings
Dim font As New Aurigma.GraphicsMill.Drawing.Font("Tahoma", 20)
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center
font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Bottom

'Draw rotated line and text
Dim matrix As New System.Drawing.Drawing2D.Matrix
matrix.RotateAt(45, New System.Drawing.PointF(60, 60))
graphics.Transform = matrix

graphics.DrawLine(pen, -30, 60, 150, 60)
graphics.DrawString("Sample text", font, brush, 60, 60)
```
 
```csharp
//Create Bitmap object
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 120, 120, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

Aurigma.GraphicsMill.Drawing.Pen pen = 
    new Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Black, 1);

Aurigma.GraphicsMill.Drawing.SolidBrush brush = 
    new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

//Adjust font settings
Aurigma.GraphicsMill.Drawing.Font font = new Aurigma.GraphicsMill.Drawing.Font("Tahoma", 20);
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center;
font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Bottom;

//Draw rotated line and text
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.RotateAt(45, new System.Drawing.PointF(60, 60));
graphics.Transform = matrix;

graphics.DrawLine(pen, -30, 60, 150, 60);
graphics.DrawString("Sample text", font, brush, 60, 60);
```
 
**Note** 
When you try to draw outlined text on a grayscale bitmap (with [Format8bppGrayScale](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_PixelFormat.htm.md) pixel format), you will notice that the text is looking ragged (without antialiasing). The reason of this problem is that neither GDI nor GDI+ support grayscale bitmaps, and therefore Graphics Mill for .NET has to imitate it as Format8bppIndexed bitmap with grayscale palette. However, antialiasing is impossible on indexed bitmaps.
 
## See Also
  
### Reference
 
- [Font Class](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_Font.htm.md)
- [GdiGraphics Class](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_GdiGraphics.htm.md)
- [GdiGraphics.DrawString Overload](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawString.htm.md)
- [Font.MeasureString(String) Method](https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Drawing_Font_MeasureString_1_bb3a7a4f.htm.md)

### Manual
 
- [Measuring Text Size](https://www.graphicsmill.com/docs/gm5/MeasuringTextSize.htm.md)
