我一直在嘗試在我的 WinForm 應(yīng)用程序上獲取自定義字體。然而,似乎無論我做什么,字體都無法正確呈現(xiàn)。它確實(shí).ttf顯示在我的標(biāo)簽上,只是不太好。這是我得到的結(jié)果:底部的兩個標(biāo)簽“0%”和“2.6MB”都是“Courier New”。一旦我正確渲染了頂部標(biāo)簽,我就會切換它們。我的代碼與上述答案幾乎相同(以下所有代碼都在FormLoad中運(yùn)行):// Create a private font collection object.PrivateFontCollection pfc = new PrivateFontCollection();// Select the font from 'Resources'.// My font here is "Volter__28Goldfish_29.ttf".int fontLength = Properties.Resources.Volter__28Goldfish_29.Length;// Create a buffer to read in to.byte[] fontdata = Properties.Resources.Volter__28Goldfish_29;// Create an unsafe memory block for the font data.IntPtr data = Marshal.AllocCoTaskMem(fontLength);// Copy the bytes to the unsafe memory block.Marshal.Copy(fontdata, 0, data, fontLength);// Pass the font to the font collection.pfc.AddMemoryFont(data, fontLength);// Set custom font.lblUpdate.Font = new Font(pfc.Families[0], 8);
1 回答

侃侃爾雅
TA貢獻(xiàn)1801條經(jīng)驗 獲得超16個贊
我認(rèn)為這太明顯了,不可能是真的……我的問題是我的字體大小是或者6F
是8F
,我不認(rèn)為奇數(shù)是正確的大小。我所要做的就是將其更改為7F
.
因此,如果您的像素字體看起來很丑,我將保留這篇文章作為警告。仔細(xì)檢查您輸入的字體大小是否正確。
(注意:如果您未將該屬性設(shè)置UseCompatibleTextRendering
為,您的字體也可能會顯得有些扭曲True
)
- 1 回答
- 0 關(guān)注
- 77 瀏覽
添加回答
舉報
0/150
提交
取消