GraphicsPath.AddString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將文字字串加入這個路徑。
多載
AddString(String, FontFamily, Int32, Single, Point, StringFormat)
將文字字串加入這個路徑。
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)
參數
- family
- FontFamily
FontFamily,表示用來描繪測試的字型名稱。
- emSize
- Single
限制字元的 Em 方形的高度。
- format
- StringFormat
StringFormat,指定文字格式資訊,例如行的間距和對齊方式。
範例
下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse
事件OnPaint物件。 此程式碼會執行下列動作:
建立路徑。
設定字串和字型自變數。
將字串新增至路徑。
將字串繪製到畫面。
有兩個重要事項要指出。首先,請注意自 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)
將文字字串加入這個路徑。
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)
參數
- family
- FontFamily
FontFamily,表示用來描繪測試的字型名稱。
- emSize
- Single
限制字元的 Em 方形的高度。
- format
- StringFormat
StringFormat,指定文字格式資訊,例如行的間距和對齊方式。
範例
如需範例,請參閱 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。
適用於
AddString(String, FontFamily, Int32, Single, Rectangle, StringFormat)
將文字字串加入這個路徑。
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)
參數
- family
- FontFamily
FontFamily,表示用來描繪測試的字型名稱。
- emSize
- Single
限制字元的 Em 方形的高度。
- format
- StringFormat
StringFormat,指定文字格式資訊,例如行的間距和對齊方式。
範例
如需範例,請參閱 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。
適用於
AddString(String, FontFamily, Int32, Single, RectangleF, StringFormat)
將文字字串加入這個路徑。
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)
參數
- family
- FontFamily
FontFamily,表示用來描繪測試的字型名稱。
- emSize
- Single
限制字元的 Em 方形的高度。
- layoutRect
- RectangleF
RectangleF,表示限定文字界限的矩形。
- format
- StringFormat
StringFormat,指定文字格式資訊,例如行的間距和對齊方式。
範例
如需範例,請參閱 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應