【问题标题】:Custom Drawing Text C#自定义绘图文本 C#
【发布时间】:2013-03-07 06:29:43
【问题描述】:

我的表单中有一个文本框,我正在向其中绘制一个字符串,如下所示。

Font myFont = new Font("Arial",18F,FontStyle.Regular,GraphicsUnit.Point,128);
Graphics g = myTextBox.CreateGraphics();
Brush b = new SolidBrush(Color.Red);
g.DrawString("Item Drawn with DrawString",myFont ,b,new PointF(1,1));

文本框中显示的字符串。然后我尝试了下面的代码

 Font myFont = new Font("Arial",18F,FontStyle.Regular,GraphicsUnit.Point,128);
 Graphics g = myTextBox.CreateGraphics();
 TextRenderer.DrawText(g,"Item Drawn with DrawText",myFont,new Point(1,1),Color.Red);

问题来了。尽管g.DrawString()TextRenderer.DrawText() 两种方法使用相同的字体,但字体样式存在差异。那就是某些字符的呈现方式不同。如果我在字体中使用“1”而不是“128”,这两种方法都会将字符呈现为唯一的。

如果我更改字体中的GdiCharSet(128) 值,而使用g.DrawString() 方法将没有效果。我的问题是为什么g.DrawString() 方法不包括GdiCharSet 值?

【问题讨论】:

    标签: c# fonts textbox customization


    【解决方案1】:

    因为这个:

    gdiCharSet 参数从 Windows SDK 头文件 WinGDI.h 中定义的列表中获取一个值。 Windows 窗体应用程序支持 TrueType 字体并且对 OpenType 字体的支持有限。如果 familyName 参数指定的字体未安装在运行应用程序的机器上或不受支持,则将替换为 Microsoft Sans Serif。

    (From the MSDN documentation)

    由于 Arial 是 TrueType 字体并且它支持 Unicode,据我所知,您不需要设置 GDI 字符集。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-01
      • 2017-11-28
      • 2014-05-17
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多