Export (0) Print
Expand All

Graphics.DrawString Method (String, Font, Brush, Single, Single, StringFormat)

Draws the specified text string at the specified location with the specified Brush and Font objects using the formatting attributes of the specified StringFormat.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

Public Sub DrawString ( _
	s As String, _
	font As Font, _
	brush As Brush, _
	x As Single, _
	y As Single, _
	format As StringFormat _


Type: System.String

String to draw.

Type: System.Drawing.Font

Font that defines the text format of the string.

Type: System.Drawing.Brush

Brush that determines the color and texture of the drawn text.

Type: System.Single

The x-coordinate of the upper-left corner of the drawn text.

Type: System.Single

The y-coordinate of the upper-left corner of the drawn text.

Type: System.Drawing.StringFormat

StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text.


brush is Nothing.


s is Nothing.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a text string to draw.

  • Defines the font as Arial (16pt).

  • Creates a solid, black brush to draw with.

  • Creates the coordinates of a point for the upper-left corner at which to draw the text.

  • Sets the format of the string to draw vertically

  • Draws the string to the screen using the font, brush, destination point, and format.

Public Sub DrawStringFloatFormat(ByVal e As PaintEventArgs)

    ' Create string to draw. 
    Dim drawString As [String] = "Sample Text" 

    ' Create font and brush. 
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create point for upper-left corner of drawing. 
    Dim x As Single = 150.0F
    Dim y As Single = 50.0F

    ' Set format of string. 
    Dim drawFormat As New StringFormat
    drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

    ' Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, _
    x, y, drawFormat)
End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft