I have a multi-lined TextBox
. I have also an Input
box used in specifying a Regex string that is used in formatting the text that is entered in the TextBox
.
Regex.Replace
replaces strings. What I want is to apply some styling to the found matched as using Bold, Italic and ch开发者_如何学Pythonange its ForeColor.
For Example:
Text in TextBox
:
Change all text in the multi-lined text box that matches the text inside the input box's text box
String in Input Box/Regex:
text
And I have:
RegexOptions.IgnoreCase
The desired result:
Change all text in the multi-lined text box that matches the text inside the input box's text box
You need to use a RichTextBox
for this. First use the RegEx to find the indexes of the sub strings and then use SelectionStart
and SelectionEnd
to select that text in the RTB and SelectionFont
and SelectionColor
to make it bold and colored.
精彩评论