我正在尝试将嵌入式资源字体更改为我的 RichTextBox。但它不工作。它适用于标签,但不适用于我的富文本框。将字体更改为richtextbox 后,我在控制台中写出了我的richtextbox 的字体名称,它拼出了正确的名称,但它并没有改变屏幕上的字体。
这是我的代码
//define a private font collection
System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
//read your resource font into a byte array
byte[] Bytes = Properties.Resources.BRAILLE11;
//allocate some memory and get a pointer to it
IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(Bytes.Length);
//copy the font data byte array to memory
System.Runtime.InteropServices.Marshal.Copy(Bytes, 0, ptr, Bytes.Length);
//Add the font to the private font collection
pfc.AddMemoryFont(ptr, Bytes.Length);
//free up the previously allocated memory
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
//define a font from the private font collection
System.Drawing.Font fnt = new System.Drawing.Font(pfc.Families[0], 16f, System.Drawing.FontStyle.Regular, GraphicsUnit.Point);
//dispose of the private font collection
pfc.Dispose();
//return the font created from your font resource
richTextBoxEditor.Font = fnt;
lblStatus.Font = fnt;
Console.Write(richTextBoxEditor.Font.Name);
fnt.Dispose();