1

How can I change the Font.Size in a RichTextBox .SelectionFont (which has two or three different FontFamily), without affecting the FontFamilyand the FontStyle

This one works fine, if I have only one Font.Family

richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont.FontFamily, 12);

But, if I have more, it throws nullexception.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Consider using this great textbox component: http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting – oo_dev Apr 21 '15 at 08:40
  • RichTextBox.SelectionFont returns null if there are different fonts selected. You´ll have to write logic using RichTextBox.Select to change around your selection and set the Fonts individually for each Font.Family – Nils O Apr 21 '15 at 08:41

2 Answers2

0

Perhaps this answer from the question: "Reset RTF in RichTextBox?" may help you. I quote:

More you ask?

I use most of this via a small utility class that wraps this for all the styles and font changes. This way you can change font-size and not change font name, etc.

Community
  • 1
  • 1
Dan W
  • 3,520
  • 7
  • 42
  • 69
0

I've had the same problem. Check the answer by LarsTech here:

Changing font for richtextbox without losing formatting

You'll find properties such as SelectionFontName, SelectionFontSize, ...

Community
  • 1
  • 1
Jerry
  • 4,258
  • 3
  • 31
  • 58