Вопрос

Hey all i am trying to load my custom ttf font and also have it AntiAlias so it doesnt look all jagged and all.

The code in order to load the custom font is this (found here):

Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("C:\Path To\PALETX3.ttf")
label1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)

The code to do the Antialias on fonts is this (found 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))

However, i am not able to merge those codes above... I've tried:

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

But an error of:

Overload resolution failed because no accessible 'New' accepts this number of arguments.

That is on the Dim fontFamily As New Font(font.Families(0)) line.

Any help to merge these 2 together would be great!

Это было полезно?

Решение

New Font has over a dozen overloads for new and you happen to pick one not in the list. The very minimum when specifying args is:

Dim myFont As New Font(familyName As String, emSize as integer) 

so try this:

Dim myFont As New Font(font.Families(0), 16) 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top