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);
}
}
|