1
嘿我試圖打電話給我的嵌入字體亞伯拉罕·林肯到我的標籤,雖然當我運行它從不改變字體程序...呼叫嵌入式字體到標籤
Private Sub slackerR_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim sMyFonts As String() = {"AbrahamLincoln.ttf"}
Dim fEmbedded As New Font(GetFont(sMyFonts).Families(0), 10)
Label1.Font = fEmbedded
End Sub
Public Function GetFont(ByVal FontResource() As String) As Drawing.Text.PrivateFontCollection
'Get the namespace of the application
Dim NameSpc As String = Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString()
Dim FntStrm As IO.Stream
Dim FntFC As New Drawing.Text.PrivateFontCollection()
Dim i As Integer
For i = 0 To FontResource.GetUpperBound(0)
'Get the resource stream area where the font is located
FntStrm = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(NameSpc + "." + FontResource(i))
'Load the font off the stream into a byte array
Dim ByteStrm(CType(FntStrm.Length, Integer)) As Byte
FntStrm.Read(ByteStrm, 0, Int(CType(FntStrm.Length, Integer)))
'Allocate some memory on the global heap
Dim FntPtr As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(Runtime.InteropServices.Marshal.SizeOf(GetType(Byte)) * ByteStrm.Length)
'Copy the byte array holding the font into the allocated memory.
Runtime.InteropServices.Marshal.Copy(ByteStrm, 0, FntPtr, ByteStrm.Length)
'Add the font to the PrivateFontCollection
FntFC.AddMemoryFont(FntPtr, ByteStrm.Length)
'Free the memory
Runtime.InteropServices.Marshal.FreeHGlobal(FntPtr)
Next
Return FntFC
End Function
我都試過{「AbrahamLincoln.ttf」}和{「AbrahamLincoln」}和兩者都不起作用。
使用VB.net 2010
查找範圍的輸出窗口「第一次機會例外」通知。 –
代碼行中類型爲'System.NullReferenceException'**的@HansPassant ** ** Dim ByteStrm(CType(FntStrm.Length,Integer))作爲字節** – StealthRT
[VS2010的可能重複未顯示未處理的異常消息在64位版本的Windows上的WinForms應用程序](http://stackoverflow.com/questions/4933958/vs2010-does-not-show-unhandled-exception-message-in-a-winforms-application-on-a) –