Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.

How to insert leading dots before tab positions

Topics for Thursday, August 05 2004

How to insert leading dots before tab positions

Click to enlarge

Everybody knows them: the small leading dots between the items and the prices on a menu card or between a heading and a page number in a table of contents.

The screenshot to the right illustrates this principle.

This week we would like to show you a simple way to insert these leading dots in TX Text Control .NET. The technique that we describe is very simple, but at the same time, very efficient. When the user presses the tab key, the gap between the text and the next tab position is filled with dots.

How to do that? First of all, we store the starting position on the KeyDown event. We need this position to know where to start with the dots.

In the KeyUp event, we store the new input position, which is our end position. After that we use a loop to insert the dots using the Text property of the current selection. It loops until the current position equals the end position we stored previously.

We use the InputPosition class to compare the horizontal positions. That is all there is to it.

  1. Do While startPosLocation.X <= endPosLocation.X - 40
  2. TextControl1.Selection.Text = "."
  3. startPosLocation = TextControl1.InputPosition.Location
  4. Loop

As mentioned, this is a very basic method to insert these leading dots. Consider improvements like reordering the dots, if the tab position has been changed. This is more complex as you have to store the paragraphs where leading dots have been inserted.

Please download Download [10.48 KB, ZIP] the full source code for this sample.

The minimum requirements for this sample application are TX Text Control .NET trial version and Visual Studio .NET 2003.

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