dcsimg
October 19, 2018
Hot Topics:

Extending the TextBox Control

  • November 20, 2002
  • By Joacim Andersson
  • Send Email »
  • More Articles »

As we all know the strength of VB is it's simplicity. Just draw some controls onto a form set some properties during design time, write some "glue code" and you're done (well, almost anyway). VB also provides us with ready to go controls that are the same as Windows own controls (i.e. TextBox, ListBox, CommandButton and so on) or are they?

Windows own controls have more properties then those available in VB. Properties that Microsoft was too lazy to include or just didn't think a VB developer needed.

Take an ordinary multiline textbox for example. It is almost the same as a Windows edit box except for the lack of several properties. An edit box has a property which the VB developer can use to retrieve the number of lines of text it contains. You are also able to get the index of the first visible line (almost like the TopIndex property of a list box) for example.

But is there a way to harness the power of these hidden properties? Luckily there is! With the help of the SendMessage API function you can extend an ordinary textbox so you can treat the lines of text as an array of strings. This is very useful when you want to parse the text. Let's say that you want to create an HTML editor and you want to add color coding (just like the editor in VB itself). Wouldn't it be very useful then if you could extract just the line of text the text caret is on and examines that text for the HTML tags you want to add colors to? Of course it would! But how do you add colors to a textbox you ask? Well, actually you can't. But the code I'm going to show you could as easily be used on a rich text box as well as a standard textbox.

Let's go to work!





Page 1 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date