2012-07-23 55 views
1

我想要一個特定的字體顯示在應用程序中的某些按鈕上,所以選擇將其作爲資源包含在項目中。VB.Net嵌入式字體在Windows XP中不工作

然後,我通過Marshal命名空間的方式將.addMemoryFont添加到新的PrivateFontCollection,然後將字體設置爲我的新字體系列。

這適用於Windows Vista,Windows7和Windows 8(預覽),但不適用於我的應用必須支持的Windows XP。

在XP上沒有錯誤..字體只是不顯示。

我也曾嘗試嵌入字體的文件,並加載它通過一個流對象 - Assembly.GetExecutingAssembly()GetManifestResourceStream(資源)

這一切再次工作,但XP,有什麼想法?謝謝

下面是我加載資源的功能: 對於這個測試,我已經將AVP.TTF(廣泛可用的,非商業的)添加爲稱爲AVP的資源。

我在客戶端使用button.Font = LoadFontResource(9.75,FontStyle.Regular)。

Public Function LoadFontResource(ByVal Size As Single, ByVal style As FontStyle) As Font 
    _fontsResource = New PrivateFontCollection 
    Dim fontMemPointer As IntPtr = Marshal.AllocCoTaskMem(My.Resources.AVP.Length) 
    Marshal.Copy(My.Resources.AVP, 0, fontMemPointer, My.Resources.AVP.Length) 
    _fontsResource.AddMemoryFont(fontMemPointer, My.Resources.AVP.Length) 
    Marshal.FreeCoTaskMem(fontMemPointer) 
    Return New Font(_fontsResource.Families(0), Size, style) 
End Function 
+0

重現問題的郵政編碼和麻煩字體的鏈接。 – 2012-07-23 14:26:53

+0

爲什麼你需要支持Windows XP。在不到17個月的時間裏,它甚至不會得到微軟的支持。 – 2012-07-23 14:37:47

+0

@Hans:添加代碼 – Sunrise 2012-07-23 15:06:58

回答

0

將嵌入字體寫入臨時文件,然後使用.AddFontFile可以在XP中產生更穩定的性能。感謝漢斯將我指向舊的GDI +路線。