2013-03-07 25 views
-1

我在窗體中有一個TextBox,我正在繪製一個字符串,如下所示。自定義繪圖文本C#

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

回答

0

正因爲如此:

的gdiCharSet參數需要從Windows SDK頭文件中定義WINGDI.H列表中的值。 Windows窗體應用程序支持TrueType字體,並且對OpenType字體的支持有限。如果familyName參數指定運行應用程序的計算機上未安裝的字體或不支持的字體,則將替換Microsoft Sans Serif。

From the MSDN documentation

因爲Arial字體是TrueType字體,並支持Unicode,你不應該需要進行設置GDI字符集,據我所知。