TX Text Control Source Code Library

Implementing AutoText with TX Text Control

One of the most sought after features in a word processing application is that of AutoText or AutoCompletion. The screenshot to the right illustrates this feature. Typically, AutoCompletion is implemented at the end user application level, due to the different requirements of every application.

In this short sample application, you will learn how to implement AutoCompletion in a TX Text Control based word processing application.

All we need is a customized word list and an algorithm to suggest the words. In the sample zip, you will find a word list with over 120.000 words. These strings are copied into an ArrayList.

Dim oFile As System.IO.File Dim reader As System.IO.StreamReader = _ oFile.OpenText("wordlist.txt") Dim line As String = reader.ReadLine() While Not line Is Nothing wordList.Add(line) line = reader.ReadLine() End While

As the user types some initial letters and presses CTRL + SPACE, a ComboBox is filled with all words starting with these letters. This ComboBox is displayed at the current input position in TX Text Control.

For Each word As String In wordList If word.StartsWith(startsWith) = True Then If Not ComboBox1.Items.Contains(word) Then ComboBox1.Items.Add(word) End If End If Next

The variable startsWith is the last found word from the current input position. To get the last word, the function getLastWord() searches for spaces or carriage returns in the text, in order to return the last typed string. If the user selects a word in the ComboBox and presses Enter, the word is inserted into the TX Text Control.

To use the downloadable version of this sample at least a TX Text Control .NET for Windows Forms 11.0 trial version is required.

 
 

Products

Support

Downloads

Corporate

Buy Now