* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
2.2 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|
| How to: Set Tab Stops in Drawn Text | 03/30/2017 |
|
|
64878f98-39ba-4303-b63f-0859ab682eeb |
How to: Set Tab Stops in Drawn Text
You can set tab stops for text by calling the xref:System.Drawing.StringFormat.SetTabStops%2A method of a xref:System.Drawing.StringFormat object and then passing that xref:System.Drawing.StringFormat object to the xref:System.Drawing.Graphics.DrawString%2A method of the xref:System.Drawing.Graphics class.
Note
The xref:System.Windows.Forms.TextRenderer?displayProperty=nameWithType does not support adding tab stops to drawn text, although you can expand existing tab stops using the xref:System.Windows.Forms.TextFormatFlags.ExpandTabs?displayProperty=nameWithType flag.
Example
The following example sets tab stops at 150, 250, and 350. Then, the code displays a tabbed list of names and test scores.
The following illustration shows the tabbed text:
The following code passes two arguments to the xref:System.Drawing.StringFormat.SetTabStops%2A method. The second argument is an array that contains tab offsets. The first argument passed to xref:System.Drawing.StringFormat.SetTabStops%2A is 0, which indicates that the first offset in the array is measured from position 0, the left edge of the bounding rectangle.
[!code-csharpSystem.Drawing.FontsAndText#41] [!code-vbSystem.Drawing.FontsAndText#41]
Compiling the Code
- The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs
e, which is a parameter of xref:System.Windows.Forms.PaintEventHandler.
