Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-draw-text-at-a-specified-location.md
T
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

3.1 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Draw Text at a Specified Location 03/30/2017
csharp
vb
text [Windows Forms], drawing at specified locations [Windows Forms]
drawing text
drawing text [Windows Forms], specified locations [Windows Forms]
Windows Forms, drawing text at a specified location
60816423-1c38-465e-980d-2c2b64d74086

How to: Draw Text at a Specified Location

When you perform custom drawing, you can draw text in a single horizontal line starting at a specified point. You can draw text in this manner by using the xref:System.Drawing.Graphics.DrawString%2A overloaded method of the xref:System.Drawing.Graphics class that takes a xref:System.Drawing.Point or xref:System.Drawing.PointF parameter. The xref:System.Drawing.Graphics.DrawString%2A method also requires a xref:System.Drawing.Brush and xref:System.Drawing.Font

You can also use the xref:System.Windows.Forms.TextRenderer.DrawText%2A overloaded method of the xref:System.Windows.Forms.TextRenderer that takes a xref:System.Drawing.Point. xref:System.Windows.Forms.TextRenderer.DrawText%2A also requires a xref:System.Drawing.Color and a xref:System.Drawing.Font.

The following illustration shows the output of text drawn at a specified point when you use the xref:System.Drawing.Graphics.DrawString%2A overloaded method.

Screenshot that shows the output of text at a specified point.

To draw a line of text with GDI+

  1. Use the xref:System.Drawing.Graphics.DrawString%2A method, passing the text you want, xref:System.Drawing.Point or xref:System.Drawing.PointF, xref:System.Drawing.Font, and xref:System.Drawing.Brush.

    [!code-csharpSystem.Drawing.AlignDrawnText#30] [!code-vbSystem.Drawing.AlignDrawnText#30]

To draw a line of text with GDI

  1. Use the xref:System.Windows.Forms.TextRenderer.DrawText%2A method, passing the text you want, xref:System.Drawing.Point, xref:System.Drawing.Font, and xref:System.Drawing.Color.

    [!code-csharpSystem.Drawing.AlignDrawnText#40] [!code-vbSystem.Drawing.AlignDrawnText#40]

Compiling the Code

The previous examples require:

See also