How to preserve current font/style while making changes to RTF text in C#
Windows Forms?
Using Visual Studio to create a Windows Forms application, using C#. I
have a RichTextBox. This box supports formatting like colours, bold, and
underline.
I've added buttons such that people can format their text right in the
box. For example, the Bold button does this:
if (!message.SelectionFont.Bold)
message.SelectionFont = new Font(message.Font, FontStyle.Bold);
else
message.SelectionFont = new Font(message.Font, FontStyle.Regular);
This works fine for bolding and unbolding regular text. The issue is when
it is combined with other formatting. The creation of a new Font wipes
away the original formatting, and leaves me with pure bold or pure regular
text.
How can I preserve original formatting, while changing text to bold?
It shouldn't be hard-coded. I shouldn't be checking if(bold), if(italics),
if(underline) for every option, as ideally I'll be adding more options
later (colour, font, font size, etc).
No comments:
Post a Comment