I created a simple WinForm Form
and tested a custom font file.
Basically I just add several chinese characters (which do not exist) to
a existing font file.
Strange thing is that the font only works in WinForm controls such as TextBox
, Grid..etc. but does not work when I use Paint event of the Form
or Picturebox
.
As You can see in the picture, the first character showed perfectly in the TextBox
but not showed when I use the DrawString()
in the Form
Paint event.
Of course, every other ordinary characters are displaying perfectly.
Code:
Private custfont As Font
Private drawBrush As New SolidBrush(Color.Black)
Private chinese_string As String = "英世"
Private Sub frmTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim count As Integer = 0
Dim familyname As String = ""
Dim fontFamilies() As FontFamily
Dim private_fontCollection As New PrivateFontCollection
private_fontCollection.AddFontFile("e:\UNI_HSR_EXT42.TTF")
fontFamilies = private_fontCollection.Families
count = fontFamilies.Length
familyname = fontFamilies(0).Name
Dim ff As FontFamily = New FontFamily(familyname, private_fontCollection)
custfont = New Font(ff, 20, FontStyle.Regular)
Me.TextBox1.Font = custfont
Me.TextBox1.Text = chinese_string
End Sub
Private Sub frmTest_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawString(chinese_string, custfont, drawBrush, 50, 50)
End Sub