--- title: "How to: Draw Text with GDI" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "GDI [Windows Forms], drawing text [Windows Forms]" - "text [Windows Forms], drawing with TextRenderer" - "drawing [Windows Forms], text" - "Windows Forms, drawing text with GDI" ms.assetid: 2a19fe5d-2ace-451c-94db-01cb1118ef7b --- # How to: Draw Text with GDI With the method in the class, you can access GDI functionality for drawing text on a form or control. GDI text rendering typically offers better performance and more accurate text measuring than GDI+. > [!NOTE] > The methods of the class are not supported for printing. When printing, always use the methods of the class. ## Example The following code example demonstrates how to draw text on multiple lines within a rectangle using the method. [!code-csharp[System.Windows.Forms.TextRendererExamples#7](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.TextRendererExamples/CS/Form1.cs#7)] [!code-vb[System.Windows.Forms.TextRendererExamples#7](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.TextRendererExamples/VB/Form1.vb#7)] To render text with the class, you need an , such as a and a , a location to draw the text, and the color in which it should be drawn. Optionally, you can specify the text formatting by using the enumeration. For more information about obtaining a , see [How to: Create Graphics Objects for Drawing](how-to-create-graphics-objects-for-drawing.md). For more information about constructing a , see [How to: Construct Font Families and Fonts](how-to-construct-font-families-and-fonts.md). ## Compiling the Code The preceding code example is designed for use with Windows Forms, and it requires the `e`, which is a parameter of . ## See also - - - - [Using Fonts and Text](using-fonts-and-text.md)