本文整理汇总了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);
}
}