Friday, September 21, 2007

Another OwnerDraw Example - This Time Adding Red Squiggles to Text in a TextBox

Coded - Web Development and Programming Blog - Owner-drawing a Windows.Forms TextBox

"This article describes how SharpSpell is able to modify existing TextBox controls to display wavy red underlines below misspelled words.

Here’s an image to demonstrate what I mean:

SharpSpell - ASP.NET spell checker
(This image is borrowed from SharpSpell, but you get the point)

...

Now to use this class, you just need to instantiate it by passing a TextBox control to the constructor. Make sure you keep a reference to it at the module level so it doesn’t get eaten by the Garbage Collector.

CustomPaintTextBox customUnderlines = new CustomPaintTextBox(textBox1);

I haven’t really tested this stripped out version of the class, but it should work. Most of it is taken directly from the SharpSpell source code.

I hope this article helps you understand how to owner draw native Win32 controls using the .NET framework. If you have any questions please leave a comment."

This is a cool short C# article on owner drawing a textbox, providing a nice example of both text measuring and adding visual status indicators.

(via Larkware News - The Daily Grind 1234)

2 comments:

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...