Επεξεργασία

Κοινή χρήση μέσω


Font.GetHeight Method

Definition

Returns the line spacing of this font.

Overloads

GetHeight()

Returns the line spacing, in pixels, of this font.

GetHeight(Graphics)

Returns the line spacing, in the current unit of a specified Graphics, of this font.

GetHeight(Single)

Returns the height, in pixels, of this Font when drawn to a device with the specified vertical resolution.

GetHeight()

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

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

Returns

The line spacing, in pixels, of this font.

Remarks

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.

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. For example, suppose the font unit is inches and the font size is 0.3. Also suppose that for the corresponding font family, the em-height is 2048 and the line spacing is 2355. 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.11719

Applies to

GetHeight(Graphics)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

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
Public Function GetHeight (graphics As Graphics) As Single

Parameters

graphics
Graphics

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.

Returns

The line spacing, in pixels, of this font.

Exceptions

graphics is null.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a 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

Remarks

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.

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 specified Graphics object. For example, suppose the font unit is inches and the font size is 0.3. Also suppose that for the corresponding font family, the em-height is 2048 and the line spacing is 2355. If 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.1171875

Continuing with the same example, suppose the Unit property of the Graphics object is set to GraphicsUnit.Millimeter rather than GraphicsUnit.Pixel. Then (using 1 inch = 25.4 millimeters) the height, in millimeters, is calculated as follows:

2355*(0.3/2048)25.4 = 8.762256

See also

Applies to

GetHeight(Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

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

Parameters

dpi
Single

The vertical resolution, in dots per inch, used to calculate the height of the font.

Returns

The height, in pixels, of this Font.

Remarks

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. For example, suppose the font unit is inches and the font size is 0.3. Also suppose that for the corresponding font family, the em-height is 2048 and the line spacing is 2355. If the specified vertical resolution is 96 dots per inch, the height is calculated as follows:

2355*(0.3/2048)*96 = 33.1171875

See also

Applies to