Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-draw-text-on-a-windows-form.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

2.0 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Draw Text on a Windows Form 03/30/2017
csharp
vb
cpp
forms [Windows Forms], drawing text
text [Windows Forms], drawing
5d2447a9-21a1-4adc-b954-5516f2bb9b2c

How to: Draw Text on a Windows Form

The following code example shows how to use the xref:System.Drawing.Graphics.DrawString%2A method of the xref:System.Drawing.Graphics to draw text on a form. Alternatively, you can use xref:System.Windows.Forms.TextRenderer for drawing text on a form. For more information, see How to: Draw Text with GDI.

Example

[!code-cppSystem.Drawing.ConceptualHowTos#7] [!code-csharpSystem.Drawing.ConceptualHowTos#7] [!code-vbSystem.Drawing.ConceptualHowTos#7]

Compiling the Code

You cannot call the xref:System.Drawing.Graphics.DrawString%2A method in the xref:System.Windows.Forms.Form.Load event handler. The drawn content will not be redrawn if the form is resized or obscured by another form. To make your content automatically repaint, you should override the xref:System.Windows.Forms.Control.OnPaint%2A method.

Robust Programming

The following conditions may cause an exception:

  • The Arial font is not installed.

See also