Export (0) Print
Expand All

Graphics.DrawString Method (String, Font, Brush, PointF)

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)

public void DrawString(
	string s,
	Font font,
	Brush brush,
	PointF point
)

Parameters

s
Type: System.String
String to draw.
font
Type: System.Drawing.Font
Font that defines the text format of the string.
brush
Type: System.Drawing.Brush
Brush that determines the color and texture of the drawn text.
point
Type: System.Drawing.PointF
PointF structure that specifies the upper-left corner of the drawn text.

ExceptionCondition
ArgumentNullException

brush is null.

-or-

s is null.

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.


public void DrawStringPointF(PaintEventArgs e)
{

    // Create string to draw.
    String drawString = "Sample Text";

    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);

    // Create point for upper-left corner of drawing.
    PointF drawPoint = new PointF(150.0F, 150.0F);

    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft