GraphicsPath.AddString Method

Definition

Adds a text string to this path.

Overloads

AddString(String, FontFamily, Int32, Single, Point, StringFormat)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Adds a text string to this path.

C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat? format);
C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat format);

Parameters

s
String

The String to add.

family
FontFamily

A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

A FontStyle enumeration that represents style information about the text (bold, italic, and so on). This must be cast as an integer (see the example code later in this section).

emSize
Single

The height of the em square box that bounds the character.

origin
Point

A Point that represents the point where the text starts.

format
StringFormat

A StringFormat that specifies text formatting information, such as line spacing and alignment.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

  • Creates a path.

  • Sets up string and font arguments.

  • Adds the string to the path.

  • Draws the string to the screen.

There are two important things to be pointed out. First, notice that the fontStyle argument is cast as an integer. The AddString method requires this so that two or more FontStyle members can be combined to create the desired font style (in this case, Italic and Underline). Secondly, notice that the FillPath method is used rather than the DrawPath method. If FillPath is used, solid text is rendered, whereas if DrawPath is used, the text will be an outline style.

C#
private void AddStringExample(PaintEventArgs e)
{
             
    // Create a GraphicsPath object.
    GraphicsPath myPath = new GraphicsPath();
             
    // Set up all the string parameters.
    string stringText = "Sample Text";
    FontFamily family = new FontFamily("Arial");
    int fontStyle = (int)FontStyle.Italic;
    int emSize = 26;
    Point origin = new Point(20, 20);
    StringFormat format = StringFormat.GenericDefault;
             
    // Add the string to the path.
    myPath.AddString(stringText,
        family,
        fontStyle,
        emSize,
        origin,
        format);
             
    //Draw the path to the screen.
    e.Graphics.FillPath(Brushes.Black, myPath);
}

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddString(String, FontFamily, Int32, Single, PointF, StringFormat)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Adds a text string to this path.

C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat? format);
C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat format);

Parameters

s
String

The String to add.

family
FontFamily

A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

A FontStyle enumeration that represents style information about the text (bold, italic, and so on). This must be cast as an integer (see the example code later in this section).

emSize
Single

The height of the em square box that bounds the character.

origin
PointF

A PointF that represents the point where the text starts.

format
StringFormat

A StringFormat that specifies text formatting information, such as line spacing and alignment.

Examples

For an example, see AddString(String, FontFamily, Int32, Single, Point, StringFormat).

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Adds a text string to this path.

C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat? format);
C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat format);

Parameters

s
String

The String to add.

family
FontFamily

A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

A FontStyle enumeration that represents style information about the text (bold, italic, and so on). This must be cast as an integer (see the example code later in this section).

emSize
Single

The height of the em square box that bounds the character.

layoutRect
Rectangle

A Rectangle that represents the rectangle that bounds the text.

format
StringFormat

A StringFormat that specifies text formatting information, such as line spacing and alignment.

Examples

For an example, see AddString(String, FontFamily, Int32, Single, Point, StringFormat).

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Adds a text string to this path.

C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat? format);
C#
public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat format);

Parameters

s
String

The String to add.

family
FontFamily

A FontFamily that represents the name of the font with which the test is drawn.

style
Int32

A FontStyle enumeration that represents style information about the text (bold, italic, and so on). This must be cast as an integer (see the example code later in this section).

emSize
Single

The height of the em square box that bounds the character.

layoutRect
RectangleF

A RectangleF that represents the rectangle that bounds the text.

format
StringFormat

A StringFormat that specifies text formatting information, such as line spacing and alignment.

Examples

For an example, see AddString(String, FontFamily, Int32, Single, Point, StringFormat).

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10