GraphicsPath.AddString Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a text string to this path.
Overloads
AddString(String, FontFamily, Int32, Single, Point, StringFormat) |
Adds a text string to this path. |
AddString(String, FontFamily, Int32, Single, PointF, StringFormat) |
Adds a text string to this path. |
AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat) |
Adds a text string to this path. |
AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat) |
Adds a text string to this path. |
AddString(String, FontFamily, Int32, Single, Point, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
Adds a text string to this path.
public:
void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::Point origin, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat? format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.Point * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As Point, format As StringFormat)
Parameters
- 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.
- 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.
private:
void AddStringExample( PaintEventArgs^ e )
{
// Create a GraphicsPath object.
GraphicsPath^ myPath = gcnew GraphicsPath;
// Set up all the string parameters.
String^ stringText = "Sample Text";
FontFamily^ family = gcnew FontFamily( "Arial" );
int fontStyle = (int)FontStyle::Italic;
int emSize = 26;
Point origin = Point(20,20);
StringFormat^ format = StringFormat::GenericDefault;
// Add the string to the path.
myPath->AddString( stringText, family, fontStyle, (float)emSize, origin, format );
//Draw the path to the screen.
e->Graphics->FillPath( Brushes::Black, myPath );
}
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);
}
Public Sub AddStringExample(ByVal e As PaintEventArgs)
' Create a GraphicsPath object.
Dim myPath As New GraphicsPath
' Set up all the string parameters.
Dim stringText As String = "Sample Text"
Dim family As New FontFamily("Arial")
Dim myfontStyle As Integer = CInt(FontStyle.Italic)
Dim emSize As Integer = 26
Dim origin As New Point(20, 20)
Dim format As StringFormat = StringFormat.GenericDefault
' Add the string to the path.
myPath.AddString(stringText, family, myfontStyle, emSize, _
origin, format)
'Draw the path to the screen.
e.Graphics.FillPath(Brushes.Black, myPath)
End Sub
Applies to
AddString(String, FontFamily, Int32, Single, PointF, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
Adds a text string to this path.
public:
void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::PointF origin, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat? format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.PointF * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As PointF, format As StringFormat)
Parameters
- 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.
- 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
AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
Adds a text string to this path.
public:
void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::Rectangle layoutRect, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat? format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.Rectangle * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, layoutRect As Rectangle, format As StringFormat)
Parameters
- 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.
- 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
AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
Adds a text string to this path.
public:
void AddString(System::String ^ s, System::Drawing::FontFamily ^ family, int style, float emSize, System::Drawing::RectangleF layoutRect, System::Drawing::StringFormat ^ format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat? format);
public void AddString (string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat format);
member this.AddString : string * System.Drawing.FontFamily * int * single * System.Drawing.RectangleF * System.Drawing.StringFormat -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, layoutRect As RectangleF, format As StringFormat)
Parameters
- 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).