Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Implementing AutoText with TX Text Control

This source code snippet requires TX Text Control .NET
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 Download [620.32 KB, ZIP]
Click to enlarge

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.

  1. Dim oFile As System.IO.File
  2. Dim reader As System.IO.StreamReader = _
  3. oFile.OpenText("wordlist.txt")
  4. Dim line As String = reader.ReadLine()
  5.  
  6. While Not line Is Nothing
  7. wordList.Add(line)
  8. line = reader.ReadLine()
  9. 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.

  1. For Each word As String In wordList
  2. If word.StartsWith(startsWith) = True Then
  3. If Not ComboBox1.Items.Contains(word) Then
  4. ComboBox1.Items.Add(word)
  5. End If
  6. End If
  7. 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.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place