The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
1 VB 5 Custom Controls &nbsp

TextBoxEx Control

Implement an extended version of the TextBox control by using the API directly

TextBox Control As An Editor With Line Numbers

Download Code
VB5 code Download the complete TextBoxEx source code (91kb)

&nbsp Before you Begin &nbsp
&nbsp This project requires the SSubTmr.DLL component. Make sure you have downloaded and registered this before trying the project. &nbsp
&nbsp This project requires the IShellFolder Extended Type Library v1.2 (ISHF_Ex.TLB) when running in the IDE. Make sure you have downloaded and registered this before trying the project. &nbsp
&nbsp This project requires the Ole Guids and Interface Definitions type library (OleGuids.TLB) when running in the IDE. Make sure you have downloaded and registered this before trying the project. &nbsp

The TextBoxEx control is a new version of the TextBox control showing some of the things that the VB TextBox should be capable of by default. It is another excellent project from Mike Gainer, although I should point out that I have modified some of the code so if it doesn't work correctly then you should probably contact me!

How to Build a TextBox
The limitations of the VB TextBox control are quite surprising, and most of them have survived from the original release of Visual Basic to the current version. The VB TextBox control seems to ignore all interface enhancements that were added with Windows 95. Similarly, the design hasn't grown to allow you the flexibility to change parameters at design time rather than run-time.

The TextBoxEx control is a building block component demonstrating how easy it would be for VB's coders to add extra features to the TextBox but how difficult it can be from Visual Basic to create and host a control created directly from the base Win32 API. The additional design features and options provided in this control are:
    Design Time or Run Time style changes. Rather than accepting limitations on when control styles can be changed this control provides complete flexibility and all styles can be changed, including which ScrollBars are visible and whether the control is MultiLine or SingleLine, at any time.

    Supporting All the TextBox's features. The standard VB TextBox control can't fail but disappoint by leaving out obvious and often required features such as support for Cut, Copy, Paste, Delete,Undo, Left and Right Margins, determining the Current Line, Current Column, First Visible Line, raising events when the text is scrolled, allowing text to be scrolled into view and so forth.

    Customising the TextBox for Your App. And then there is customisation. This TextBox can accept TabStops and vary the number of spaces per tab. You can control the response to the Tab and Shift-Tab key combinations to allow multi-line indent and outdent just like VB. The Context Menu can be disabled. You can stop the control raising Change events for maximum speed.
Tough Code
Whilst this is a seriously flexible TextBox, it is primarily a great project for picking apart if you want to learn about coding controls from first principles using the API in VB. The code is the source for the Simpler UserControl Tab Trapping DLL ,which provides a generic mechanism to make a Window created using the CreateWindowEx API call appear part of the TabStop Order in an ActiveX control host (i.e. VB, IE, Word etc).

Other useful tips include using the IFont object to manage VB and API fonts at the same time and intercepting the WM_CONTEXTMENU call to allow either a default or customised right-click menu to be shown.

About The Sample Code
The demonstration sample is a half-assed effort to complete a useful replacement for Notepad. I don't know about you, but basically the program I want is the same program as Notepad, except it also has these features:
  1. VB style Find/Replace
  2. New Window
  3. Block Indent/Outdent with Tab
  4. Readable Print-Out, with headers, page numbers and user definable font.
  5. Auto-Complete.
Oh alright then, I'm only kidding about the Auto-Complete! The sample project provided with the control is an attempt at moving towards my goal, in that it goes some way to achieve items 2 and 3, but the implementation of the other items is either not present or rubbish.

It does provide a nice line-numbering side bar, though, based on an original implementation for a RichEdit control by David Miles (thanks!).

Who wants to take on the challenge of the other two? And what about more features for simple, quick, 64k TextEditor? We're obviously not going to take on CodeWright here, but the result could be seriously speedy and intently focused. Send your ideas and code in to me ( and we'll see what we can do to build an Editor like its, erm, 1997!

TopBack to top
Source Code - What We're About!Back to ActiveX Control Source Code
Source Code - What We're About!Back to Source Code


AboutContributeSend FeedbackPrivacy

Copyright 1998-1999, Steve McMahon ( All Rights Reserved.
Last updated: 15 August 1999