通过


Font.GetHeight 方法

定义

返回此字体的行距。

重载

名称 说明
GetHeight()

返回此字体的行距(以像素为单位)。

GetHeight(Graphics)

返回此字体的当前单位 Graphics中的行距。

GetHeight(Single)

当绘制到具有指定垂直分辨率的设备时,返回此 Font 高度(以像素为单位)。

GetHeight()

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
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

返回

此字体的行距(以像素为单位)。

注解

a Font 的行距是两个连续文本行的底线之间的垂直距离。 因此,行距包括行之间的空白空间以及字符本身的高度。

Unit如果字体的属性设置为其他GraphicsUnit.Pixel任何内容,则使用屏幕显示器的垂直分辨率计算高度(以像素为单位)。 例如,假设字体单位为英寸,字号为 0.3。 另外,假设对于相应的字体系列,em 高度为 2048,行距为 2355。 对于垂直分辨率为 96 点/英寸的屏幕显示器,可以按如下所示计算高度:

2355*(0.3/2048)*96 = 33.11719

适用于

GetHeight(Graphics)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
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
Graphics

Graphics保存显示设备的垂直分辨率(以点/英寸为单位),以及页面单位和页面缩放的设置。

返回

此字体的行距(以像素为单位)。

例外

graphicsnull

示例

下面的代码示例旨在与 Windows 窗体一起使用,它需要 PaintEventArgse,这是事件处理程序的参数 Paint 。 该代码执行以下操作:

  • 创建 Font

  • 使用新文本向屏幕绘制一 Font行文本。

  • 获取字体的高度。

  • 在第一行下方绘制第二行文本。

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

注解

a Font 的行距是两个连续文本行的底线之间的垂直距离。 因此,行距包括行之间的空白空间以及字符本身的高度。

Unit如果字体的属性设置为其他GraphicsUnit.Pixel任何内容,则使用指定Graphics对象的垂直分辨率计算高度(以像素为单位)。 例如,假设字体单位为英寸,字号为 0.3。 另外,假设对于相应的字体系列,em 高度为 2048,行距为 2355。 Graphics如果对象具有Unit属性值和GraphicsUnit.PixelDpiY每英寸 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
Source:
Font.cs
Source:
Font.cs
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 高度为 2048,行距为 2355。 如果指定的垂直分辨率为每英寸 96 点,则计算高度,如下所示:

2355*(0.3/2048)*96 = 33.1171875

另请参阅

适用于