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

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

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?

Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Also

The text rendering offered by the TextRenderer class is based on GDI text rendering and is not supported for printing from Windows Forms. Instead, use the DrawString methods of the Graphics class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.