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 行間は、連続する 2 行のテキストの基本行間の垂直方向の距離です。 したがって、行間には、行間の空白スペースと文字自体の高さが含まれます。

フォントの Unit プロパティが 以外 GraphicsUnit.Pixelに設定されている場合、高さ (ピクセル単位) は、画面表示の垂直方向の解像度を使用して計算されます。 たとえば、フォント単位がインチで、フォント サイズが 0.3 であるとします。 また、対応するフォント ファミリの場合、em-height は 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

ページの単位とページのスケールの設定、および表示デバイスの垂直解像度 (dpi) を保持する Graphics

戻り値

フォントの行間 (ピクセル単位)。

例外

graphicsnullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • Font を作成します。

  • 新しい Fontを使用して、画面にテキストの行を描画します。

  • フォントの高さを取得します。

  • 1 行目のすぐ下に 2 行目のテキストを描画します。

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 行間は、連続する 2 行のテキストの基本行間の垂直方向の距離です。 したがって、行間には、行間の空白スペースと文字自体の高さが含まれます。

フォントの Unit プロパティが 以外に GraphicsUnit.Pixel設定されている場合、指定した Graphics オブジェクトの垂直方向の解像度を使用して、高さがピクセル単位で計算されます。 たとえば、フォント単位がインチで、フォント サイズが 0.3 であるとします。 また、対応するフォント ファミリの場合、em-height は 2048 で、行間は 2355 であるとします。 オブジェクトの Graphics プロパティ値が UnitGraphicsUnit.PixelDpiY プロパティ値が 96 ドット/インチの場合、高さは次のように計算されます。

2355*(0.3/2048)*96 = 33.1171875

同じ例を続けて、オブジェクトの プロパティが UnitGraphics ではなく GraphicsUnit.PixelGraphicsUnit.Millimeter設定されるとします。 次に、(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-height は 2048 で、行間は 2355 であるとします。 指定した垂直方向の解像度が 96 ドット/インチの場合、高さは次のように計算されます。

2355*(0.3/2048)*96 = 33.1171875

こちらもご覧ください

適用対象