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 for Windows Forms. 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.
Do While startPosLocation.X <= endPosLocation.X - 40
TextControl1.Selection.Text = "."
startPosLocation = TextControl1.InputPosition.Location
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.
The minimum requirements for this sample application are TX Text Control .NET for Windows Forms trial version and Visual Studio .NET 2003.
The Newsletter Team