当前位置: 首页>>代码示例>>C#>>正文


C# FontFamily.GetEmHeight方法代码示例

本文整理汇总了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));
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:15,代码来源:FontFamily.GetEmHeight

示例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());
    }
}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:58,代码来源:FontFamily.GetEmHeight


注:本文中的System.Drawing.FontFamily.GetEmHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。