自定义绘图文本使用特定字体 [英] Custom Drawing Text using specific Font

查看:140
本文介绍了自定义绘图文本使用特定字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的表格中有一个TextBox,我正在画一个字符串,如下所示。



Hi All,

I have a TextBox in my Form and I am drawing a string into it as below.

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));





TextBox中显示的字符串。然后我尝试下面的代码





The string displayed in the TextBox. Then I tried below code

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值?



Here the problem comes. Even though two methods g.DrawString() and TextRenderer.DrawText() uses same font, there is a difference in font style. That is some characters are rendered differently. If I use "1" instead of "128" in the font both methods will render characters as unique.

If I change GdiCharSet(128) value in font, while using g.DrawString() method there will be no effect. My question is why g.DrawString() method excludes GdiCharSet value?

推荐答案

这是一个很好的问题。你必须下载这些电话的来源才能找到。



Graphics.cs这只有一个版本还有其他版本

That''s a good question. You''ll have to download the source for those calls to find out.

Graphics.cs this is only one version there are others
public void DrawString(String s, Font font, Brush brush,RectangleF layoutRectangle, StringFormat format) 
{
   if (brush == null)
      throw new ArgumentNullException("brush"); 
   if (s == null || s.Length == 0)
      return; 
   if (font == null) 
      throw new ArgumentNullException("font");
 
   GPRECTF grf = new GPRECTF(layoutRectangle);
   IntPtr nativeStringFormat = (format == null) ? IntPtr.Zero : format.nativeFormat;
   int status = SafeNativeMethods.Gdip.GdipDrawString(new HandleRef(this, this.NativeGraphics),s, s.Length, new HandleRef(font, font.NativeFont), ref grf, new HandleRef(format,nativeStringFormat), new HandleRef(brush, brush.NativeBrush));
 
   //check error status sensitive to TS problems
   CheckErrorStatus(status); 
}





另一个我无法轻易找到的功能。

你可以从微软获取源代码。有在Visual Studio中使用它的说明,以便您可以单步执行它。



希望有所帮助。

Gregg



The other function I was not able to find so easily.
You can get the source from microsoft. There are instructions for using it in Visual Studio so that you can step through it.

Hope that helps.
Gregg


这篇关于自定义绘图文本使用特定字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆