Font.GetHeight Font.GetHeight Font.GetHeight Font.GetHeight Method

定義

傳回這個字型的行距。Returns the line spacing of this font.

多載

GetHeight() GetHeight() GetHeight() GetHeight()

傳回這個字型的行距 (單位為像素)。Returns the line spacing, in pixels, of this font.

GetHeight(Graphics) GetHeight(Graphics) GetHeight(Graphics)

傳回這個字型的行距 (單位是指定之 Graphics 的目前單位)。Returns the line spacing, in the current unit of a specified Graphics, of this font.

GetHeight(Single) GetHeight(Single) GetHeight(Single) GetHeight(Single)

傳回這個 Font 在使用指定之垂直解析度繪製至裝置時的高度 (單位為像素)。Returns the height, in pixels, of this Font when drawn to a device with the specified vertical resolution.

GetHeight() GetHeight() GetHeight() GetHeight()

傳回這個字型的行距 (單位為像素)。Returns the line spacing, in pixels, of this font.

public:
 float GetHeight();
public float GetHeight ();
member this.GetHeight : unit -> single
Public Function GetHeight () As Single

傳回

這個字型的行距 (單位為像素)。The line spacing, in pixels, of this font.

備註

的行距Font是兩個連續行文字的基本線條之間的垂直距離。The line spacing of a Font is the vertical distance between the base lines of two consecutive lines of text. 因此, 行距會在行之間包含空格, 以及字元本身的高度。Thus, the line spacing includes the blank space between lines along with the height of the character itself.

如果字型的GraphicsUnit.Pixel屬性設定為以外的任何內容,則會使用螢幕顯示的垂直解析度來計算高度(以圖元Unit為單位)。If the Unit property of the font is set to anything other than GraphicsUnit.Pixel, the height (in pixels) is calculated using the vertical resolution of the screen display. 例如, 假設字型單位為英寸, 字型大小為0.3。For example, suppose the font unit is inches and the font size is 0.3. 此外, 假設針對對應的字型系列, em 高度為 2048, 而行距為2355。Also suppose that for the corresponding font family, the em-height is 2048 and the line spacing is 2355. 對於垂直解析度為每英寸96個點的螢幕畫面, 您可以計算高度, 如下所示:For a screen display that has a vertical resolution of 96 dots per inch, you can calculate the height as follows:

2355*(0.3/2048)*96 = 33.117192355*(0.3/2048)*96 = 33.11719

GetHeight(Graphics) GetHeight(Graphics) GetHeight(Graphics)

傳回這個字型的行距 (單位是指定之 Graphics 的目前單位)。Returns the line spacing, in the current unit of a specified Graphics, of this font.

public:
 float GetHeight(System::Drawing::Graphics ^ graphics);
public float GetHeight (System.Drawing.Graphics graphics);
member this.GetHeight : System.Drawing.Graphics -> single

參數

graphics
Graphics Graphics Graphics Graphics

Graphics,其保留顯示裝置的垂直解析度 (單位為 DPI) 以及頁面單位和頁面縮放的設定。A Graphics that holds the vertical resolution, in dots per inch, of the display device as well as settings for page unit and page scale.

傳回

這個字型的行距 (單位為像素)。The line spacing, in pixels, of this font.

例外狀況

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計, 而且PaintEventArgs它需要e, 這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 建立 FontCreates a Font.

  • 使用新Font的, 將一行文字繪製到螢幕上。Draws a line of text to the screen, using the new Font.

  • 取得字型的高度。Gets the height of the font.

  • 在第一行的正下方繪製第二行文字。Draws a second line of text directly below the first line.

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是兩個連續行文字的基本線條之間的垂直距離。The line spacing of a Font is the vertical distance between the base lines of two consecutive lines of text. 因此, 行距會在行之間包含空格, 以及字元本身的高度。Thus, the line spacing includes the blank space between lines along with the height of the character itself.

如果字型的GraphicsUnit.Pixel Graphics屬性設定為以外的任何內容, 則會使用指定物件的垂直解析度來計算高度 (以圖元為單位)。 UnitIf the Unit property of the font is set to anything other than GraphicsUnit.Pixel, the height, in pixels, is calculated using the vertical resolution of the specified Graphics object. 例如, 假設字型單位為英寸, 字型大小為0.3。For example, suppose the font unit is inches and the font size is 0.3. 此外, 假設針對對應的字型系列, em 高度為 2048, 而行距為2355。Also suppose that for the corresponding font family, the em-height is 2048 and the line spacing is 2355. 如果物件的Unit 屬性值GraphicsUnit.Pixel為, 且屬性值為每英寸96個點,則會計算高度,如下所示:DpiY GraphicsIf the Graphics object has a Unit property value of GraphicsUnit.Pixel and a DpiY property value of 96 dots per inch, the height is calculated as follows:

2355*(0.3/2048)*96 = 33.11718752355*(0.3/2048)*96 = 33.1171875

繼續進行相同Unit的範例, 假設Graphics物件的屬性設定為GraphicsUnit.Millimeter , 而不GraphicsUnit.Pixel是。Continuing with the same example, suppose the Unit property of the Graphics object is set to GraphicsUnit.Millimeter rather than GraphicsUnit.Pixel. 然後 (使用1英寸 = 25.4 毫米) 高度 (以毫米為單位) 的計算方式如下:Then (using 1 inch = 25.4 millimeters) the height, in millimeters, is calculated as follows:

2355*(0.3/2048)25.4 = 8.7622562355*(0.3/2048)25.4 = 8.762256

另請參閱

GetHeight(Single) GetHeight(Single) GetHeight(Single) GetHeight(Single)

傳回這個 Font 在使用指定之垂直解析度繪製至裝置時的高度 (單位為像素)。Returns the height, in pixels, of this Font when drawn to a device with the specified vertical resolution.

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 Single Single Single

用來計算字型高度的垂直解析度 (單位為 DPI)。The vertical resolution, in dots per inch, used to calculate the height of the font.

傳回

這個 Font 的高度 (單位為像素)。The height, in pixels, of this Font.

備註

如果字型的GraphicsUnit.Pixel屬性設定為以外的任何內容,則會使用螢幕顯示的垂直解析度來計算高度(以圖元Unit為單位)。If the Unit property of the font is set to anything other than GraphicsUnit.Pixel, the height (in pixels) is calculated using the vertical resolution of the screen display. 例如, 假設字型單位為英寸, 字型大小為0.3。For example, suppose the font unit is inches and the font size is 0.3. 此外, 假設針對對應的字型系列, em 高度為 2048, 而行距為2355。Also suppose that for the corresponding font family, the em-height is 2048 and the line spacing is 2355. 如果指定的垂直解析度是每英寸96個點, 則高度的計算方式如下:If the specified vertical resolution is 96 dots per inch, the height is calculated as follows:

2355*(0.3/2048)*96 = 33.11718752355*(0.3/2048)*96 = 33.1171875

另請參閱

適用於