GraphicsPath.AddString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在這條路徑上加入文字串。
多載
| 名稱 | Description |
|---|---|
| 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)
在這條路徑上加入文字串。
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 A 代表用來繪製測驗的字體名稱。
- emSize
- Single
就是用來界定字元的 em 方格的高度。
- format
- StringFormat
A 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)
在這條路徑上加入文字串。
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 A 代表用來繪製測驗的字體名稱。
- emSize
- Single
就是用來界定字元的 em 方格的高度。
- format
- StringFormat
A 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 A 代表用來繪製測驗的字體名稱。
- emSize
- Single
就是用來界定字元的 em 方格的高度。
- format
- StringFormat
A 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 A 代表用來繪製測驗的字體名稱。
- emSize
- Single
就是用來界定字元的 em 方格的高度。
- layoutRect
- RectangleF
A RectangleF 代表了將文字界定為邊界的矩形。
- format
- StringFormat
A StringFormat 指定文字格式資訊,如行距與對齊。
範例
如需範例,請參閱 AddString(String, FontFamily, Int32, Single, Point, StringFormat)。