本文整理汇总了C#中System.Drawing.FontFamily.GetEmHeight方法的典型用法代码示例。如果您正苦于以下问题:C# FontFamily.GetEmHeight方法的具体用法?C# FontFamily.GetEmHeight怎么用?C# FontFamily.GetEmHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.FontFamily
的用法示例。
在下文中一共展示了FontFamily.GetEmHeight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEmHeight_Example
public void GetEmHeight_Example(PaintEventArgs e)
{
// Create a FontFamily object.
FontFamily emFontFamily = new FontFamily("arial");
// Get the em height of the font family in design units.
int emHeight = emFontFamily.GetEmHeight(FontStyle.Regular);
// Draw the result as a string to the screen.
e.Graphics.DrawString(
"emFontFamily.GetEmHeight() returns " + emHeight.ToString() + ".",
new Font(emFontFamily, 16),
Brushes.Black,
new PointF(0, 0));
}
示例2: OnPaint
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
FontFamily ff = new FontFamily("Times New Roman");
float emSizeInGU = 24f;
Font f = new Font(ff, emSizeInGU);
int emSizeInDU = ff.GetEmHeight(FontStyle.Regular);
int ascentInDU = ff.GetCellAscent(FontStyle.Regular);
int descentInDU = ff.GetCellDescent(FontStyle.Regular);
int lineSpacingInDU = ff.GetLineSpacing(FontStyle.Regular);
float ascentInGU = ascentInDU * (emSizeInGU / emSizeInDU);
float descentInGU = descentInDU * (emSizeInGU / emSizeInDU);
float lineSpacingInGU = lineSpacingInDU * (emSizeInGU / emSizeInDU);
PointF textOrigin = new PointF(20, 20);
PointF nextLineOrigin = new PointF(textOrigin.X,textOrigin.Y + f.Height);
g.DrawString("AxgQ", f, Brushes.Black, textOrigin);
g.DrawString("AxgQ", f, Brushes.Black, nextLineOrigin);
int lineLen = 100;
g.DrawLine(Pens.Blue,textOrigin,new PointF(textOrigin.X + lineLen, textOrigin.Y));
g.DrawLine(Pens.Red,nextLineOrigin,new PointF(nextLineOrigin.X + lineLen, nextLineOrigin.Y));
PointF p = new PointF(textOrigin.X,textOrigin.Y + lineSpacingInGU);
g.DrawLine(Pens.Blue, p,new PointF(p.X + lineLen, p.Y));
p = new PointF(nextLineOrigin.X,nextLineOrigin.Y + lineSpacingInGU);
g.DrawLine(Pens.Red, p,new PointF(p.X + lineLen, p.Y));
p = new PointF(textOrigin.X,textOrigin.Y + lineSpacingInGU - ascentInGU);
g.DrawLine(Pens.Blue, p,new PointF(p.X + lineLen, p.Y));
p = new PointF(nextLineOrigin.X, nextLineOrigin.Y +lineSpacingInGU - ascentInGU);
g.DrawLine(Pens.Red, p, new PointF(p.X + lineLen, p.Y));
p = new PointF(textOrigin.X,textOrigin.Y + lineSpacingInGU + descentInGU);
g.DrawLine(Pens.Blue, p,new PointF(p.X + lineLen, p.Y));
p = new PointF(nextLineOrigin.X,nextLineOrigin.Y + lineSpacingInGU + descentInGU);
g.DrawLine(Pens.Red, p,new PointF(p.X + lineLen, p.Y));
}
public static void Main() {
Application.Run(new Form1());
}
}