

MultiStringDecoration: Selects based on String.IndexOf for a list of given strings.StringDecoration: Selects based on String.IndexOf for a given string.MultiExplicitDecoration: Selects based on a list of starting character positions and number of characters.ExplicitDecoration: Selects based on a starting character position and the number of characters.I have included eight Decoration classes. Please note that the list is dependent on the text involved. The classes used to select the text for decoration are all derived from the abstract base class Decoration. I also needed to take care of scrolling, text coloring, background coloring, underlining, and strikethroughs. I expected that in time I could have quite a number of them. As the original purpose of this control was to highlight text affected by Regular Expressions in various ways, I needed an extensible method for making text selections. There were several issues that needed to be taken care of. Text coloring rules are set through the Decorations property. Hopefully, I will be able to remove this nonstandard behavior soon. In order to set the background color, just wrap it in a border. In order to set the default text color, use the BaseForeground property. This is done in the constructor so all one needs to do is not set them. The background and foreground brushes should both be set to something transparent. This control can be used like a regular textbox with the following caveats. It exceeded my expectations, so here it is. I figured that this couldn’t possibly be slower than the RichTextBox, so I gave it a try. Selecting and editing will be handled by the underling text box functionality.The original text's brush can be set to something transparent so it will not cover up the decorated text.Since both sets of text are visible, I can make sure that they line up exactly.Recreate the same text as was in the textbox, but colorized and otherwise decorated.It took a few moments to progress from Oh that’s odd to Wow, my problem is solved, as I could now do the following. I was surprised to find that both the textbox’s text and my additional text were visible, as I expected only my overridden text to appear. For the heck of it, I overrode the OnRender method, and wrote a little text to the TextBox. I had tried numerous times to somehow get performance that compared to the WinForms RichTextBox, but failed. My problem was the painful slowness of the RichTextBox control. For the n th time, I was considering moving it from WinForms to WPF. I was in the process of upgrading a Regular Expression generating tool of mine. As it is derived from the TextBox control, rather than the RichTextBox, it is quite speedy. This article presents an enhanced text box control that is designed to facilitate text coloring, highlighting, underlining, and striking.
