Font.GetHeight 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回此字体的行距。
重载
GetHeight() |
返回此字体的行距(以像素为单位)。 |
GetHeight(Graphics) |
采用指定的 Graphics 的当前单位,返回此字体的行距。 |
GetHeight(Single) |
当用指定的垂直分辨率绘制到设备时,返回此 Font 的高度(以像素为单位)。 |
GetHeight()
- Source:
- Font.cs
- Source:
- Font.cs
- Source:
- Font.cs
返回此字体的行距(以像素为单位)。
public:
float GetHeight();
public float GetHeight ();
member this.GetHeight : unit -> single
Public Function GetHeight () As Single
返回
此字体的行距(以像素为单位)。
注解
的 Font 行距是两个连续文本行的基线之间的垂直距离。 因此,行距包括行之间的空格以及字符本身的高度。
Unit如果字体的 属性设置为 以外的GraphicsUnit.Pixel任何值,则使用屏幕显示的垂直分辨率计算高度 () 像素。 例如,假设字体单位为英寸,字号为 0.3。 此外,假设对于相应的字体系列,em-height 为 2048,行距为 2355。 对于垂直分辨率为每英寸 96 点的屏幕显示器,可以按如下所示计算高度:
2355*(0.3/2048)*96 = 33.11719
适用于
GetHeight(Graphics)
- Source:
- Font.cs
- Source:
- Font.cs
- Source:
- Font.cs
采用指定的 Graphics 的当前单位,返回此字体的行距。
public:
float GetHeight(System::Drawing::Graphics ^ graphics);
public float GetHeight (System.Drawing.Graphics graphics);
member this.GetHeight : System.Drawing.Graphics -> single
Public Function GetHeight (graphics As Graphics) As Single
参数
返回
此字体的行距(以像素为单位)。
例外
graphics
为 null
。
示例
下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse
,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:
public:
void GetHeight_Example( PaintEventArgs^ e )
{
// Create a Font object.
System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",16 );
//Draw text to the screen with myFont.
e->Graphics->DrawString( "This is the first line", myFont, Brushes::Black, PointF(0,0) );
//Get the height of myFont.
float height = myFont->GetHeight( e->Graphics );
//Draw text immediately below the first line of text.
e->Graphics->DrawString( "This is the second line", myFont, Brushes::Black, PointF(0,height) );
}
public void GetHeight_Example(PaintEventArgs e)
{
// Create a Font object.
Font myFont = new Font("Arial", 16);
//Draw text to the screen with myFont.
e.Graphics.DrawString("This is the first line",myFont,
Brushes.Black, new PointF(0, 0));
//Get the height of myFont.
float height = myFont.GetHeight(e.Graphics);
//Draw text immediately below the first line of text.
e.Graphics.DrawString(
"This is the second line",
myFont,
Brushes.Black,
new PointF(0, height));
}
Public Sub GetHeight_Example(ByVal e As PaintEventArgs)
' Create a Font object.
Dim myFont As New Font("Arial", 16)
'Draw text to the screen with myFont.
e.Graphics.DrawString("This is the first line", myFont, _
Brushes.Black, New PointF(0, 0))
'Get the height of myFont.
Dim height As Single = myFont.GetHeight(e.Graphics)
'Draw text immediately below the first line of text.
e.Graphics.DrawString("This is the second line", myFont, _
Brushes.Black, New PointF(0, height))
End Sub
注解
的 Font 行距是两个连续文本行的基线之间的垂直距离。 因此,行距包括行之间的空格以及字符本身的高度。
Unit如果字体的 属性设置为以外的GraphicsUnit.Pixel任何值,则使用指定Graphics对象的垂直分辨率计算高度(以像素为单位)。 例如,假设字体单位为英寸,字号为 0.3。 此外,假设对于相应的字体系列,em-height 为 2048,行距为 2355。 Graphics如果 对象的属性值GraphicsUnit.Pixel为 Unit ,DpiY属性值为每英寸 96 点,则高度计算如下:
2355*(0.3/2048)*96 = 33.1171875
继续同一示例,假设 Unit 对象的 属性 Graphics 设置为 GraphicsUnit.Millimeter 而不是 GraphicsUnit.Pixel。 然后,使用 1 英寸 = 25.4 毫米) 高度(以毫米为单位)的 (计算结果如下:
2355*(0.3/2048)25.4 = 8.762256
另请参阅
适用于
GetHeight(Single)
- Source:
- Font.cs
- Source:
- Font.cs
- Source:
- Font.cs
当用指定的垂直分辨率绘制到设备时,返回此 Font 的高度(以像素为单位)。
public:
float GetHeight(float dpi);
public float GetHeight (float dpi);
member this.GetHeight : single -> single
Public Function GetHeight (dpi As Single) As Single
参数
- dpi
- Single
用于计算字体高度的垂直分辨率,以每英寸的点数为单位。
返回
此 Font 的高度(以像素为单位)。
注解
Unit如果字体的 属性设置为 以外的GraphicsUnit.Pixel任何值,则使用屏幕显示的垂直分辨率计算高度 () 像素。 例如,假设字体单位为英寸,字号为 0.3。 此外,假设对于相应的字体系列,em-height 为 2048,行距为 2355。 如果指定的垂直分辨率为每英寸 96 点,则高度计算如下:
2355*(0.3/2048)*96 = 33.1171875
另请参阅
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈