GraphicsPath.AddString 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
向此路径添加文本字符串。
重载
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)
参数
- family
- FontFamily
一个 FontFamily,表示绘制文本所用字体的名称。
- emSize
- Single
限定字符的 Em(字体大小)方框的高度。
- format
- StringFormat
指定文本格式设置信息(如行间距和对齐方式)的 StringFormat。
示例
下面的代码示例设计用于 Windows 窗体,它需要 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)
- 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)
参数
- family
- FontFamily
一个 FontFamily,表示绘制文本所用字体的名称。
- emSize
- Single
限定字符的 Em(字体大小)方框的高度。
- 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)
参数
- family
- FontFamily
一个 FontFamily,表示绘制文本所用字体的名称。
- emSize
- Single
限定字符的 Em(字体大小)方框的高度。
- 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)
参数
- 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 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈