Export (0) Print
Expand All

Graphics.DrawString Method

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

Overload List

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

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, PointF)
[C#] public void DrawString(string, Font, Brush, PointF);
[C++] public: void DrawString(String*, Font*, Brush*, PointF);
[JScript] public function DrawString(String, Font, Brush, PointF);

Draws the specified text string in the specified rectangle with the specified Brush and Font objects.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, RectangleF)
[C#] public void DrawString(string, Font, Brush, RectangleF);
[C++] public: void DrawString(String*, Font*, Brush*, RectangleF);
[JScript] public function DrawString(String, Font, Brush, RectangleF);

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

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, PointF, StringFormat)
[C#] public void DrawString(string, Font, Brush, PointF, StringFormat);
[C++] public: void DrawString(String*, Font*, Brush*, PointF, StringFormat*);
[JScript] public function DrawString(String, Font, Brush, PointF, StringFormat);

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, RectangleF, StringFormat)
[C#] public void DrawString(string, Font, Brush, RectangleF, StringFormat);
[C++] public: void DrawString(String*, Font*, Brush*, RectangleF, StringFormat*);
[JScript] public function DrawString(String, Font, Brush, RectangleF, StringFormat);

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, Single, Single)
[C#] public void DrawString(string, Font, Brush, float, float);
[C++] public: void DrawString(String*, Font*, Brush*, float, float);
[JScript] public function DrawString(String, Font, Brush, float, float);

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

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, Single, Single, StringFormat)
[C#] public void DrawString(string, Font, Brush, float, float, StringFormat);
[C++] public: void DrawString(String*, Font*, Brush*, float, float, StringFormat*);
[JScript] public function DrawString(String, Font, Brush, float, float, StringFormat);

Example

[Visual Basic, C#] The following 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.
[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of DrawString. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub DrawStringFloatFormat(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 = 150F
Dim y As Single = 50F
' 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
        
[C#] 
public void DrawStringFloatFormat(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.
float x = 150.0F;
float y =  50.0F;
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

Show:
© 2014 Microsoft