Hey folks,
I am developing an app using WinForms and the RichTextBox control. This control allows different changes to the RTF formatting using a property to change the font of the selected text. I have a button to toggle bold on the text:
richTextBoxEditor.SelectionFont = new Font(richTextBoxEditor.SelectionFont,
richTextBoxEditor.SelectionFont.Style ^ FontStyle.Bold);
My other buttons (italic, underline) have identical code except for the FontStyle.Bold part which is changed for the appropriate formatting.
Now the problem with this is, if I write "Hello World" and change the "Hello" to say italic, and then I try to change the whole "Hello World" to bold, "Hello" loses its italic. I understand why it does this (because the enum for the whole selection is empty so when I toggle bold, the italic flag remains to 0), but I am trying to find a way to overcome this. I can't think of anything short of going character by character and changing style individually.
Would you guys have any better idea?
Thanks.