문제

I´m trying to change to embedded resource font to my RichTextBox. But it is'nt working. It works fine on a label, but not on my richtextbox. After changing font to richtextbox I write out the font name of my richtextbox in the console, and it spells out the right name, but it is'nt changing the font on screen.

Here is my code

//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();
도움이 되었습니까?

해결책

I think the rich textbox can have text with more than one font like Bold,Italics and others in a single TextBox. So you have to select all Text First. see. http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionfont.aspx

다른 팁

is the Properties.Resources.BRAILLE11 a .bin file or a .ttf file?

Check out these links:

  1. Embedding a font into an application
  2. Rhymes with Amharic (a.k.a. How about a little breakfast embed, dear?)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top