嘿所有我想加载我的自定义ttf字体并且还有它AntiAlias所以它看起来并不是所有的锯齿状。
加载自定义字体的代码是(找到here):
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("C:\Path To\PALETX3.ttf")
label1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)
在字体上执行Antialias的代码就是这个(找到here):
Dim fontFamily As New FontFamily("Times New Roman")
Dim font As New Font( _
fontFamily, _
32, _
FontStyle.Regular, _
GraphicsUnit.Pixel)
Dim solidBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
Dim string1 As String = "SingleBitPerPixel"
Dim string2 As String = "AntiAlias"
e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel
e.Graphics.DrawString(string1, font, solidBrush, New PointF(10, 10))
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias
e.Graphics.DrawString(string2, font, solidBrush, New PointF(10, 60))
但是,我无法合并上述代码......我试过了:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim font As New PrivateFontCollection()
font.AddFontFile("C:\Path To\PALETX3.ttf")
Dim fontFamily As New Font(font.Families(0))
Dim solidBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
Dim string1 As String = "SingleBitPerPixel"
Dim string2 As String = "AntiAlias"
e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel
e.Graphics.DrawString(string1, fontFamily, solidBrush, New PointF(10, 10))
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias
e.Graphics.DrawString(string2, fontFamily, solidBrush, New PointF(10, 60))
End Sub
但错误:
重载解析失败,因为没有可访问的“新建”接受此数量的参数。
这是在 Dim fontFamily As New Font(font.Families(0))行。
将这两个合并在一起的任何帮助都会很棒!
答案 0 :(得分:0)
New Font有十几个重载的重载,你碰巧选择了一个不在列表中的。指定args时最小的是:
Dim myFont As New Font(familyName As String, emSize as integer)
所以试试这个:
Dim myFont As New Font(font.Families(0), 16)