So - I have some text in an RTF control. I want the user to be able to highlight text and apply an attribute. The following code is placed into a button called BOLD and seems to work nicely:
The code above will turn the selected text bold. Great!
But then the user selects the Same text and with the following code placed into a button called ITALIC it removes the bold attribute and replaces it with italics.
Since the users actions are separate - I can not know that they want BOLD and ITALIC, so how do I make sure I keep the existing attribute on the selected text (which, by the way could be part bold and part not-bold) and add italic?
Somehow I need to add the italic attribute to the selected text, not simply replace all attributes with italic.
Code:
If rtfText.SelectedText.Length > 0 Then
rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Bold)
End If
But then the user selects the Same text and with the following code placed into a button called ITALIC it removes the bold attribute and replaces it with italics.
Code:
If rtfText.SelectedText.Length > 0 Then
rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Italic)
End If
Somehow I need to add the italic attribute to the selected text, not simply replace all attributes with italic.
Comment