| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic .NET |
| Version: | 1.0 |
| Released: | February 17, 2004 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with Visual Basic .NET |
| Download code: | tx_sample_autotext.zip |

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 11.0 trial version is required.