难看的字体渲染

Ugly font rendering

我一直在尝试在我的 WinForm 应用程序上获取自定义字体。但是,似乎无论我做什么,字体都无法正确呈现。它是 .ttf 并且确实显示在我的标签上,只是不是很好。

我遵循了这个 Whosebug answer 但这是我得到的结果:

The two labels at the bottom '0%' & '2.6MB' are both 'Courier New'. I will switch them over once I have got my top label rendering correctly.

我的代码与上述答案几乎相同(所有波纹管都在 FormLoad 中运行):

// 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);

我认为这太明显了,不可能是真的...我的问题是我的字体大小是 6F8F,因为我认为不是奇数将是正确的大小。我所要做的就是将其更改为 7F

因此,如果您的像素字体看起来很丑,我会保留此 post 作为警告。仔细检查您输入的字体大小是否正确。

(注意: 如果您没有将 属性 UseCompatibleTextRendering 设置为 True,您的字体也可能看起来有些变形)