Microsoft Word and Visual Studio have one very cool feature in common -- squiggly underlining of errors. As of richedit 3.0 (distributed with Windows 2000 and higher, possibly also with ME) we can get these in the
RichTextBox. Actually, we can get a lot more underline styles than that...
Once again we are going to have to communicate with the underlying richedit control. This time we need to set the character format, so we'll need to add some extra stuff to our class:
+ Code to interface with the Win32
The underline style and colour are both set with the same message, so we must be careful to preserve the colour while changing the underline style. We'll use a property again so that we remain consistent with the original
+ Code to set the underline style.
Once again, this has not been fully tested so you use it at your own risk. Let me know if there are any problems, etc. The
UnderlineStyle enumeration is also fairly straightforward:
Note that some of these styles may not display correctly. This is a common problem with the richedit control, often you will apply some formatting only to find that it will not display at all. The formatting is usually stored though, so cutting and pasting into Word will show the text correctly.
We can also change the underline colour. Notice how the set method of underline colour retrieves the underline style in order to maintain consistency.
+ Code to set the underline colour.
Unfortunately there are not many colours available to this property. They are defined by the
If you set the underline colour to anything other than black it will not serialise correctly. I don't know if this is by design or not. Any text with a non-black underline that is cut and pasted into Word (or any other application) will lose it's underlining all together. I don't know if the underline is still stored in the actual rich text or not when this happens.
Well that's it for part two. In my next post in this series I will cover setting the background colour.