---
title: "GdiGraphics..::.DrawFormattedText Method (String, Font, SolidBrush, Single, Single, Single, Single, Boolean, Int32)"
canonical: https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText_9_7a086031.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/)

# GdiGraphics.DrawFormattedText Method (String, Font, SolidBrush, Single, Single, Single, Single, Boolean, Int32)
 
Draws formatted text according to its markup.
 
**Namespace:** [Aurigma.GraphicsMill.Drawing](https://www.graphicsmill.com/docs/gm5/N_Aurigma_GraphicsMill_Drawing.htm.md)
 **Assembly:** Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)
 
## Syntax
  
```
Public Sub DrawFormattedText ( _s As String, _font As Font, _brush As SolidBrush, _x As Single, _y As Single, _width As Single, _height As Single, _clipping As Boolean, _tabSize As Integer _
)
```
 
```csharp
public void DrawFormattedText(string s,Font font,SolidBrush brush,float x,float y,float width,float height,bool clipping,int tabSize
)
```
 
### Parameters
 
 - s
     - Type: [System.String](http://msdn2.microsoft.com/en-us/s1wwdcbf)
Marked up text to draw. See **Remarks** section for details on text markup requirements.

 - font
     - Type: [Aurigma.GraphicsMill.Drawing.Font](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_Font.htm.md)
 [Font](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_Font.htm.md) object specifying default text rendering options.

 - brush
     - Type: [Aurigma.GraphicsMill.Drawing.SolidBrush](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md)
 [SolidBrush](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md) object containing default font color.

 - x
     - Type: [System.Single](http://msdn2.microsoft.com/en-us/3www918f)
X-coordinate of the left top corner of the destination rectangle.

 - y
     - Type: [System.Single](http://msdn2.microsoft.com/en-us/3www918f)
Y-coordinate of the left top corner of the destination rectangle.

 - width
     - Type: [System.Single](http://msdn2.microsoft.com/en-us/3www918f)
Width of the destination rectangle.

 - height
     - Type: [System.Single](http://msdn2.microsoft.com/en-us/3www918f)
Height of the destination rectangle.

 - clipping
     - Type: [System.Boolean](http://msdn2.microsoft.com/en-us/a28wyd50)
Value specifying whether to clip the text when it does not fit the bounding rectangle. If this value is **false** all the lines of the text will be rendered regardless of the destination rectangle.

 - tabSize
     - Type: [System.Int32](http://msdn2.microsoft.com/en-us/td2s409d)
Value which specifies the number of whitespaces to replace one tabulation character in the text.
 
## Remarks
  
This method is quite similar to [DrawText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawText.htm.md) with the exception of one difference. The text you want to draw using the [DrawFormattedText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText.htm.md) method must be marked up with XML-like tags. The following tags and document structure are allowed:

```
<root>
  <para [style="..."]>
    [some text]
    <span [style="..."]>
      [some text]
        <span [style="..."]>
          [some text]
        </span>
    </span>
    ...
    <span [style="..."]></span>
  </para>
  ...
  <para [style="..."]></para>
</root>
```
  
Let us consider it more detailed:
 
**root** is the root tag. It is exactly one all over the text and includes all characters inside. If you place some text ouside the `<root></root>` tags, the [DrawFormattedText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText.htm.md) will throw an exception.
 
**para** is a paragraph tag. All the text you want to draw should be divided into paragraphs (at least one) and each of them should be enclosed between `<para>` and `</para>` tags. Otherwise, the text will not be parsed and drawn. It supports the **style** attribute (see below) to specify some text and color properties of this paragraph.
 
**span** is a tag intended to define a new inline area. You can use it to highlight some text inside a paragraph. These tags can be embedded in the existing `<span></span>` tags. It supports the **style** attribute too.
 
**Note** 
All allowed tags are case insensitive, however, the name of every opening tag must have the same case as that of the corresponding closing tag. It means that `<SpAn></SpAn>` or `<rOOt></rOOt>` pairs will be parsed successfully, but pairs like `<Para></parA>` will cause an error.
 
The text layout mechanism used in the [DrawFormattedText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText.htm.md) method is based on CSS and uses **style** attributes to attach some font, color and text parameters to paragraphs and theirs parts. This attribute accepts a string contained style parameters and corresponded values. Its common syntax is shown below:
 
```
style="style-parameter1:value1; style-parameter2:value2; ...; style-parameterN:valueN"
```
 
**Note** 
The **style** attribute and its value are case insensitive, i.e. this style setting will be applied correctly: `StyLe="fOnT-faMily: CoUriEr NeW; FoNt-siZe: 18; cOlOr:RgB(100,10,10)"`
 
All supported parameters are described in the following table:
 
|  Name |  Description |  Examples |
| --- | --- | --- |
 |  **font-family** |  Specifies a typeface name of the font.<br> <br>If font with specified typeface name is not found, system uses the first font which matches other settings (as usual it is "Arial"). |  `style="font-family:arial"` |
 |  **font-style** |  Selects between normal and italic faces within a font family. |  `style="font-style:normal"`<br> <br>`style="font-style:italic"` |
 |  **font-weight** |  Selects the weight of the font. The values `100` to `900` form an ordered sequence, where each number indicates a weight that is at least as dark as its predecessor. The keyword `normal` is synonymous with `400`, and `bold` is synonymous with `700`. |  `style="font-weight:normal"`<br> <br>`style="font-weight:bold"`<br> <br>`style="font-weight:600"` |
 |  **font-size** |  Specifies the font size. |  `style="font-size:12"` |
 |  **color** |  Specifies the text color. A numerical RGB specification is used. No keywords (such as `red`, `white`, etc) are supported. |  `style="color:rgb(200, 0, 0)"` |
 |  **text-align** |  Specifies the text alignment. The following alignment types are supported:<br> <ul> <li> <strong>center</strong> aligns text along the center.</li> <li> <strong>left</strong> aligns text along the left edge.</li> <li> <strong>right</strong> aligns text along the right edge.</li> <li> <strong>justify</strong> aligns text along the left and right edges.</li> </ul> <br>If the **justify** alignment type is specified the last line of the text can be aligned using the **textAlignLast** parameter. This parameter can be one of the following values:<br> <ul> <li> <strong>center</strong> aligns the last line of the text along the center.</li> <li> <strong>left</strong> aligns the last line of the text along the left edge.</li> <li> <strong>right</strong> aligns the last line of the text along the right edge.</li> <li> <strong>justify</strong> aligns the last line of the text along the left and right edges.</li> </ul> <br>If the **textAlignLast** parameter is not specified the last line of the text will be aligned along the left edge. |  `style="text-align:left"`<br> <br>`style="text-align:justify; textAlignLast:right"` |
 |  **\_line-spacing** |  Specifies the space between two adjacent lines of text. |  `style="_line-spacing:10px"`<br> <br>`style="_line-spacing:-15px"` |
 
The [DrawFormattedText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText.htm.md) supports the following XML predeclared entities:
 
- **`&amp;`** & ampersand;
- **`&lt;`** &lt; less than;
- **`&gt;`** &gt; greater than.

This method parses the tabulation character (`\t` in C# and `vbTab` in VB) as a sequence of whitespaces. Number of whitespaces to replace one tabulation character in the text can be specified with the `tabSize` parameter.
 
The extent of the text drawn by this method can be measured using the [Font.MeasureFormattedText](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_Font_MeasureFormattedText.htm.md) method.
 
**Note** 
The [DrawFormattedText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText.htm.md), unlike the [DrawText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawText.htm.md), does not support the newline character (`\n` in C# and `vbNewLine` in VB). To draw a string on a new line enclose it in `<para></para>` tags.
   
## See Also

### Reference

- [GdiGraphics Class](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_GdiGraphics.htm.md)
- [DrawFormattedText Overload](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawFormattedText.htm.md)
- [Aurigma.GraphicsMill.Drawing Namespace](https://www.graphicsmill.com/docs/gm5/N_Aurigma_GraphicsMill_Drawing.htm.md)
- [Font.MeasureFormattedText()](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_Font_MeasureFormattedText.htm.md)

### Manual

- [Drawing Formatted Text](https://www.graphicsmill.com/docs/gm5/DrawingFormattedText.htm.md)
