GraphicsPath.AddString 方法

定义

向此路径添加文本字符串。

重载

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

向此路径添加文本字符串。

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

向此路径添加文本字符串。

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

向此路径添加文本字符串。

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

向此路径添加文本字符串。

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

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 -> unit
Public Sub AddString (s As String, family As FontFamily, style As Integer, emSize As Single, origin As Point, format As StringFormat)

参数

s
String

要添加的 String

family
FontFamily

一个 FontFamily,表示绘制文本所用字体的名称。

style
Int32

一个 FontStyle 枚举,它表示有关文本的样式信息(粗体、斜体等)。 它必须为整数(请参见本节后面的代码示例)。

emSize
Single

限定字符的 Em(字体大小)方框的高度。

origin
Point

一个 Point,它表示文本从其起始的点。

format
StringFormat

指定文本格式设置信息(如行间距和对齐方式)的 StringFormat

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse事件OnPaint对象。 此代码执行以下操作:

  • 创建路径。

  • 设置字符串和字体参数。

  • 将字符串添加到路径。

  • 将字符串绘制到屏幕。

有两个重要的事情需要指出。首先,请注意, fontStyle 参数被强制转换为整数。 方法 AddString 需要这一点,以便可以组合两个或更多 FontStyle 个成员来创建所需的字体样式 (在这种情况下, ItalicUnderline) 。 其次,请注意, 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

向此路径添加文本字符串。

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)

参数

s
String

要添加的 String

family
FontFamily

一个 FontFamily,表示绘制文本所用字体的名称。

style
Int32

一个 FontStyle 枚举,它表示有关文本的样式信息(粗体、斜体等)。 它必须为整数(请参见本节后面的代码示例)。

emSize
Single

限定字符的 Em(字体大小)方框的高度。

origin
PointF

一个 PointF,它表示文本从其起始的点。

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

向此路径添加文本字符串。

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)

参数

s
String

要添加的 String

family
FontFamily

一个 FontFamily,表示绘制文本所用字体的名称。

style
Int32

一个 FontStyle 枚举,它表示有关文本的样式信息(粗体、斜体等)。 它必须为整数(请参见本节后面的代码示例)。

emSize
Single

限定字符的 Em(字体大小)方框的高度。

layoutRect
Rectangle

表示限定文本的矩形的 Rectangle

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

向此路径添加文本字符串。

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)

参数

s
String

要添加的 String

family
FontFamily

一个 FontFamily,表示绘制文本所用字体的名称。

style
Int32

一个 FontStyle 枚举,它表示有关文本的样式信息(粗体、斜体等)。 它必须为整数(请参见本节后面的代码示例)。

emSize
Single

限定字符的 Em(字体大小)方框的高度。

layoutRect
RectangleF

表示限定文本的矩形的 RectangleF

format
StringFormat

指定文本格式设置信息(如行间距和对齐方式)的 StringFormat

示例

有关示例,请参见 AddString(String, FontFamily, Int32, Single, Point, StringFormat)

适用于