Okay, so I am trying to use a privatefontcollection for my program to add a little bit of uniqueness to it. The font that I am using is not installed on computers by default. The font's name is youmurdererbb_reg. I have the font file in the resources folder and the file is in a .ttf format. Here is what i have so far:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Text
Dim pc As New PrivateFontCollection
Private Sub Main_Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
pc.AddFontFile(YouMurderer)
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub Main_Menu_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim Fnt As Font = New Font(pc.Families(0), 80, FontStyle.Regular)
e.Graphics.DrawString("This is the text that is being drawn", Fnt, Brushes.Black, 10, 10)
End Sub
Now where i declared the Private Font Collection, I have tried these different things to get it to work:
Dim YouMurderer As String = Encoding.ASCII.GetString(My.Resources.youmurdererbb_reg)
Dim YouMurderer As String = Convert.ToString(My.Resources.youmurdererbb_reg)
Dim YouMurderer As String = Convert.ToBase64String(My.Resources.youmurdererbb_reg)
Dim YouMurderer As String = Encoding.UTF8.GetString(My.Resources.youmurdererbb_reg)
But whichever one I choose, it just shows the entire form with a large red "X" (Like a pictureboxes' "ErrorImage") (I have a picture set to the forms background as additional information).
Another problem is that if i don't try to convert it:
Dim YouMurderer As String = My.Resources.youmurdererbb_reg
Then it comes up with the error of:
Value of type '1-dimensional array of Byte' cannot be converted to 'String'.
I need help with this in .NET (Framework 4)! The entire program is being written in VB.net, not C#, or C++, or JAVA.
I've created a library that makes this easy called BizArk. You can install it using NuGet, or, if you just want to use the source as a reference, you can get to the code here (Current/BizArkCore/Util/FontUtil.cs). Note that the code is in C#, but's there's not much code, so hopefully you should be able to follow along.
If you use the FontUtil class as it is, you can use it to create any font, even built in fonts. Here's how to use it...
Private Sub Main_Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
FontUtil.RegisterFont(My.Resources.youmurdererbb_reg)
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub Main_Menu_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim Fnt As Font = FontUtil.Create("YouMurderer", 80, FontStyle.Regular)
e.Graphics.DrawString("This is the text that is being drawn", Fnt, Brushes.Black, 10, 10)
Fnt.Dispose()
End Sub