Files
Andy De George c0ba284473 Initial winforms content migrated (#18)
* 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
2020-09-01 16:26:21 -07:00

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
csharp
vb
text [Windows Forms], drawing with tab stops
tabs [Windows Forms], drawn text
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:

Screenshot that shows a tabbed list of names and scores.

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

See also