Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2012 Label with Imported Font Error

$
0
0
I imported a font that is not supported by the Visual Studio 2012. The code is working but I'm having a problem when the label's boundary and a moving picturebox's boundary touched, the label is having an error (see image below). The error occurs when the form where the 2 objects have been closed using Me.Close() and re-open again by Form1.Show(). For people wondering why I need to close and open it again, I need it for the next level of my simple game.

Name:  error.jpg
Views: 41
Size:  9.7 KB

The code is written in my module since I'll use it in many forms. The code is below:
Code:

    Public Function custFont(data As String, ByVal size As Single, ByVal style As FontStyle) As Font
        Dim customFfont As Font
        Dim pfc = New PrivateFontCollection()
        pfc.AddFontFile(Application.StartupPath & data)
        customFont = New Font(pfc.Families(0), size, FontStyle.Regular)
        Return customFont
    End Function

Here's the sample code in my Windows Form:

Code:

    Public Class Form1
        Public Sub form1_Load() Handles MyBase.Load
            Label1.Text = "L E V E L 1"
            Label1.Font = custFont("\pixelated.TTF", 12, FontStyle.Regular)
        End Sub
    End Class

Note: pixelated.TTF is in my Debug folder.
Attached Images
 

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>