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)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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 Forms 使用,而且需要 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)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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)

適用於