本文整理匯總了C#中System.Drawing.Font.GetHeight方法的典型用法代碼示例。如果您正苦於以下問題:C# Font.GetHeight方法的具體用法?C# Font.GetHeight怎麽用?C# Font.GetHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Font
的用法示例。
在下文中一共展示了Font.GetHeight方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetHeight_Example
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));
}
示例2: Main
//引入命名空間
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);
}
}