How to: Draw Text at a Specified Location
.NET Framework (current version)
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
DrawString overloaded method of the Graphics class that takes a Point or PointF parameter. The DrawString method also requires a Brush and Font
You can also use the
DrawText overloaded method of the TextRenderer that takes a Point. DrawText also requires a Color and a Font.
The following illustration shows the output of text drawn at a specified point when you use the
DrawString overloaded method. To draw a line of text with GDI+
DrawString method, passing the text you want, Point or PointF, Font, and Brush.
Dim font1 As New Font( "Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)
Dim pointF1 As New PointF(30, 10)
e.Graphics.DrawString( "Hello", font1, Brushes.Blue, pointF1)
To draw a line of text with GDI
DrawText method, passing the text you want, Point, Font, and Color.
Dim font As New Font( "Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)
Dim point1 As New Point(30, 10)
TextRenderer.DrawText(e.Graphics, "Hello", font, point1, Color.Blue)
The previous examples require:
How to: Draw Text with GDI Using Fonts and Text How to: Construct Font Families and Fonts How to: Draw Wrapped Text in a Rectangle