0

I have a string formatting system in place in which users can use special character combinations to color text, add bold, italics, and underlines, all on a text-centered basis.

My problem is, when a user tries to bold AND underline something, for example, the text only displays the latter property. for example,

{bold char combo}{italic char combo}Hello, World

Would show up as:

Hello, World

Rather than:

Hello, World

Here's an example of the code i'm currently using.

// Other formatting codes...
case 'B': // Bold
   box.SelectionFont = new Font(box.SelectionFont, FontStyle.Bold);
   break;
case 'I': // Italic
   box.SelectionFont = new Font(box.SelectionFont, FontStyle.Italic);
   break;
// Other formatting codes...
Delta
  • 444
  • 1
  • 4
  • 14
  • Note: you use "font" in the original sense (a family of typographic characters, which are made together, same design). But the modern/computer use is to use just for one set of character. So your question is "how to select a font with specific properties" (maybe adding " from a font family"). Keep it mind, it will simplify the keyword selection when using Google. – Giacomo Catenazzi Jul 31 '20 at 09:15
  • @GiacomoCatenazzi Understandable. I'll keep that in mind next time I come across a similar issue. – Delta Aug 02 '20 at 23:53

1 Answers1

1

Found a solution.

box.SelectionFont = new Font(box.SelectionFont, box.SelectionFont.Style ^ FontStyle.Bold);

Adapted from "A way to overcome RichTextBox's limitations?"

Delta
  • 444
  • 1
  • 4
  • 14