Font.GetHeight : Font « System.Drawing « C# / C Sharp by API






Font.GetHeight

  

using System;
using System.Drawing;
using System.Windows.Forms;
   
class TextOnBaseline: Form{
     public static void Main() {
          Application.Run(new TextOnBaseline());
     }
     public TextOnBaseline() {
          ResizeRedraw = true; 
     }
     protected override void OnPaint(PaintEventArgs pea) {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy) {
          float yBaseline = cy / 2;
          Pen   pen       = new Pen(clr);
   
          grfx.DrawLine(pen, 0, yBaseline, cx, yBaseline);
   
          Font font = new Font("Times New Roman", 144);
   
          float cyLineSpace = font.GetHeight(grfx);
          int   iCellSpace  = font.FontFamily.GetLineSpacing(font.Style);
          int   iCellAscent = font.FontFamily.GetCellAscent(font.Style);
          float cyAscent    = cyLineSpace * iCellAscent / iCellSpace;
   
          grfx.DrawString("Baseline", font, new SolidBrush(clr),
                          0, yBaseline - cyAscent);
     }
}

   
    
  








Related examples in the same category

1.new Font(String fontName, int size)
2.new Font("Times New Roman", 10, FontStyle.Italic)
3.Font.FontFamily
4.Font.Height
5.Font.Name
6.Font.Size
7.Font.SizeInPoints
8.Font.Unit