|
C# and RichTextBoxes |
23yrold3yrold
Member #1,134
March 2001
|
Can someone tell me how you set the default font on one of these bastards? There's no font member to just assign a value to like most controls and every way I've tried to assign a new font family gets ignored. For the record, I need it to display in Verdana. Because it doesn't. Like, ever. -- |
akderebur
Member #13,217
August 2011
|
You can create a new font like this: You can change Verdana to anything you want: Arial, Arial Narrow, Comic Sans MS ... For setting default font just write the code after InitializeComponent. For example: using System.Drawing; public Form1() So when you start typing the font will be Verdana. |
23yrold3yrold
Member #1,134
March 2001
|
System.Windows.Forms.RichTextBox has a SelectionFont member. System.Windows.Controls.RichTextBox (which the program is using) does not. -- |
BAF
Member #2,981
December 2002
|
Umm.... richtextbox.FontFamily? |
akderebur
Member #13,217
August 2011
|
richTextBox1.FontFamily = new FontFamily("Verdana"); |
23yrold3yrold
Member #1,134
March 2001
|
Tried that, and various other things with a FontFamily member (like the richtextbox's Document). Doesn't have any effect. -- |
Neil Walker
Member #210
April 2000
|
What about FontFamily property, or am I missing something obvious Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
23yrold3yrold
Member #1,134
March 2001
|
I'm pretty sure I've tried everything obvious, but feel free to talk to me like I'm a five year old, because I feel like one right now. -- |
Neil Walker
Member #210
April 2000
|
Quote: This property only affects a control whose template uses the FontFamily property as a parameter. On other controls, this property has no impact. RichTextBox has such a parameter so it should work. http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
akderebur
Member #13,217
August 2011
|
I am not much into WPF applications but this code should work: Just debug your program using each of these: You will see the difference. |
23yrold3yrold
Member #1,134
March 2001
|
Neil Walker: So you're referring to setting the property in the XML? Or using ApplyPropertyValue()? -- |
BAF
Member #2,981
December 2002
|
Are you loading RTF into the box after attempting to set the font? According to msdn, setting that property (whether it be via XML, direct in code, or by whatever other method) will change the whole document, as well as changing the current font. |
|