Export (0) Print
Expand All

Graphics::DrawString Method (String, Font, Brush, Single, Single)

Draws the specified text string at the specified location with the specified Brush and Font objects.

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

void DrawString(
	String^ s, 
	Font^ font, 
	Brush^ brush, 
	float x, 
	float y


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.


brush is nullptr.


s is nullptr.

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 a point for the upper-left corner at which to draw the text.

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

   void DrawStringFloat( PaintEventArgs^ e )
      // Create string to draw.
      String^ drawString = "Sample Text";

      // Create font and brush.
      System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",16 );
      SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black );

      // Create point for upper-left corner of drawing. 
      float x = 150.0F;
      float y = 150.0F;

      // Draw string to screen.
      e->Graphics->DrawString( drawString, drawFont, drawBrush, x, y );

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft