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)。