GraphicsPath.AddString 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将文本字符串添加到此路径。
重载
AddString(String, FontFamily, Int32, Single, Point, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
将文本字符串添加到此路径。
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 -> unitPublic Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As Point, format As StringFormat)参数
- family
- FontFamily
一个 FontFamily,它表示用其绘制测试的字体的名称。
- emSize
- Single
边界字符的 em 方框的高度。
- format
- StringFormat
一个指定文本格式信息的 StringFormat,如行距和对齐方式。
示例
下面的代码示例旨在与 Windows 窗体一起使用,它需要 PaintEventArgseOnPaint 事件对象。 该代码执行以下操作:
- 创建路径。 
- 设置字符串和字体参数。 
- 将字符串添加到路径。 
- 将字符串绘制到屏幕。 
有两个重要事项需要指出。首先,请注意,fontStyle 参数被强制转换为整数。 
              AddString 方法要求这样做,以便可以组合两个或更多个 FontStyle 成员来创建所需的字体样式(在本例中,Italic 和 Underline)。 其次,请注意,使用 FillPath 方法而不是 DrawPath 方法。 如果使用 FillPath,则呈现纯色文本,而如果使用 DrawPath,则文本将为大纲样式。
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
适用于
AddString(String, FontFamily, Int32, Single, PointF, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
将文本字符串添加到此路径。
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 -> unitPublic Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As PointF, format As StringFormat)参数
- family
- FontFamily
一个 FontFamily,它表示用其绘制测试的字体的名称。
- emSize
- Single
边界字符的 em 方框的高度。
- format
- StringFormat
一个指定文本格式信息的 StringFormat,如行距和对齐方式。
示例
有关示例,请参阅 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。
适用于
AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
将文本字符串添加到此路径。
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 -> unitPublic Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, layoutRect As Rectangle, format As StringFormat)参数
- family
- FontFamily
一个 FontFamily,它表示用其绘制测试的字体的名称。
- emSize
- Single
边界字符的 em 方框的高度。
- format
- StringFormat
一个指定文本格式信息的 StringFormat,如行距和对齐方式。
示例
有关示例,请参阅 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。
适用于
AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
将文本字符串添加到此路径。
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 -> unitPublic Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, layoutRect As RectangleF, format As StringFormat)参数
- family
- FontFamily
一个 FontFamily,它表示用其绘制测试的字体的名称。
- emSize
- Single
边界字符的 em 方框的高度。
- layoutRect
- RectangleF
表示绑定文本的矩形的 RectangleF。
- format
- StringFormat
一个指定文本格式信息的 StringFormat,如行距和对齐方式。
示例
有关示例,请参阅 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。