好的,所以我正在尝试为我的程序使用 privatefontcollection 来为其添加一点独特性。默认情况下,我使用的字体未安装在计算机上。字体的名称是 youmurdererbb_reg。我在资源文件夹中有字体文件,该文件采用 .ttf 格式。这是我到目前为止所拥有的:
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
现在我声明了私人字体集合,我尝试了这些不同的方法来让它工作:
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)
但无论我选择哪一个,它都会用一个大的红色“X”显示整个表单(就像一个图片框的“ErrorImage”)(我有一张图片设置为表单背景作为附加信息)。
另一个问题是,如果我不尝试转换它:
Dim YouMurderer As String = My.Resources.youmurdererbb_reg
然后它出现了以下错误:
Value of type '1-dimensional array of Byte' cannot be converted to 'String'.
我需要 .NET(框架 4)中的帮助!整个程序是用 VB.net 编写的,而不是 C#、C++ 或 JAVA。