Font.GetHeight 方法

定義

傳回這個字型的行距。

多載

GetHeight()

傳回這個字型的行距 (單位為像素)。

GetHeight(Graphics)

傳回這個字型的行距 (單位是指定之 Graphics 的目前單位)。

GetHeight(Single)

傳回這個 Font 在使用指定之垂直解析度繪製至裝置時的高度 (單位為像素)。

GetHeight()

來源:
Font.cs
來源:
Font.cs
來源:
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 高度為 2048,而行距為 2355。 對於垂直解析度為每英吋 96 點的螢幕顯示器,您可以計算高度,如下所示:

2355*(0.3/2048)*96 = 33.11719

適用於

GetHeight(Graphics)

來源:
Font.cs
來源:
Font.cs
來源:
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,其保留顯示裝置的垂直解析度 (單位為 DPI) 以及頁面單位和頁面縮放的設定。

傳回

這個字型的行距 (單位為像素)。

例外狀況

graphicsnull

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 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

備註

Font 行距是兩行連續文字的基底線之間的垂直距離。 因此,行距包含行之間的空格以及字元本身的高度。

如果字 Unit 型的 屬性設定為 以外的 GraphicsUnit.Pixel任何專案,則會使用指定 Graphics 物件的垂直解析度來計算高度,以像素為單位。 例如,假設字型單位為英吋,字型大小為0.3。 此外,假設針對對應的字型系列,em 高度為 2048,而行距為 2355。 Graphics如果 物件的 屬性值GraphicsUnit.PixelUnit ,且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)

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

用來計算字型高度的垂直解析度 (單位為 DPI)。

傳回

這個 Font 的高度 (單位為像素)。

備註

如果字 Unit 型的 屬性設定為 以外的 GraphicsUnit.Pixel任何專案,則會使用螢幕顯示器的垂直解析度計算高度 (圖元) 。 例如,假設字型單位為英吋,字型大小為0.3。 此外,假設針對對應的字型系列,em 高度為 2048,而行距為 2355。 如果指定的垂直解析度為每英吋 96 點,則會計算高度,如下所示:

2355*(0.3/2048)*96 = 33.1171875

另請參閱

適用於