我正在尝试更改为我的RichTextBox的嵌入式资源字体。但它不起作用。它在标签上工作得很好,但在我的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();发布于 2012-12-14 17:10:35
我认为富文本框可以在单个TextBox中包含多种字体的文本,如粗体、斜体和其他字体。因此,您必须首先选择所有文本。看见。http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionfont.aspx
发布于 2012-12-14 16:56:11
Properties.Resources.BRAILLE11是.bin文件还是.ttf文件?
请查看以下链接:
https://stackoverflow.com/questions/13875044
复制相似问题