【问题标题】:How can I set font height in system.drawings.font?如何在 system.drawings.font 中设置字体高度?
【发布时间】:2017-03-10 08:27:48
【问题描述】:

我正在使用 C# 以某种格式编写文本。我的问题是,当我编辑字体大小时,宽度和高度都在变化,而我只想更改字体高度。

我的代码:

using (Graphics graphics = Graphics.FromImage(bitmap))
{
    using (System.Drawing.Font romanfont = new System.Drawing.Font("Times New Roman",11, FontStyle.Bold))
    //using (System.Drawing.Font romanfont = new System.Drawing.Font("Times New Roman", 11, FontStyle.Bold))
    {
        SolidBrush transBrush = new SolidBrush(Color.FromArgb(65, 79, 79));
        StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);

        graphics.DrawString(firstname, romanfont, transBrush, firstnameLocation, format);
        graphics.DrawString(secondname, romanfont, transBrush, secondnameLocation, format);
        graphics.DrawString(finalfirstadd, romanfont, transBrush, firstaddresslocation, format);
        graphics.DrawString(finalsecondadd, romanfont, transBrush, secondaddresslocation, format);
    }
}

【问题讨论】:

    标签: c# fonts height


    【解决方案1】:

    您可以通过在 Graphics 对象上设置变换来实现此效果。

    例如,如果您想让文本高一倍但宽度仍然相同,您可以这样做:

    graphics.scaleTransform(1, 2);
    

    你可以把它放在你拉弦的地方上面的任何地方。请注意,此更改将使所有内容高一倍,因此您可能需要调整矩形的位置和大小(例如firstnameLocation;在这种情况下,您可能希望将矩形的顶部和高度除以 2 .)

    【讨论】:

    • 没有其他解决办法
    猜你喜欢
    • 2012-12-28
    • 2011-11-25
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 2018-11-04
    相关资源
    最近更新 更多