In this newsletter, we are going to show you how to use the ParagraphStyle class to build a line based document index. The ParagraphStyle class inherits all properties and methods of the FormattingStyle class, which implements the functionality common to all formatting styles.
What is a line based document index? The end user loads a document, which contains styles for headings and/or subheadings. Headings can be perfectly used to navigate through a document. Consider a list in which all headings are listed and the end user is able to click an item in the list to scroll to that position in the document.
First of all, we fill a combo box with all styles that are used in the currently loaded document. This can be simply done by using the ParagraphStyles collection.
For Each myStyles In TextControl1.ParagraphStyles
If (myStyles.Name <> "[Normal]") Then
In our sample, we use a treeView control, which contains the line numbers of the specific lines, such as all the headings in the document. We use the Lines collection to parse through all lines, to check the current ParagraphStyle of the specific line. If the current style matches the selected style in the combo box, a node with the line number is created in the treeView control.
For i = 1 To TextControl1.Lines.Count
TextControl1.Selection.Start = TextControl1.Lines.Item(i).Start - 1
test = TextControl1.Selection.FormattingStyle()
If (test = ComboBox1.SelectedItem) Then
nodeString = TextControl1.Lines.Item(i).Number.ToString
The resulting treeView contains all line numbers, at which the selected style is used.
When the end user clicks on a node, TX Text Control .NET for Windows Forms scrolls to the selected line position. This can be easily achieved with the ScrollLocation property.
The minimum requirements for this sample application are TX Text Control .NET for Windows Forms trial or TX Text Control .NET for Windows Forms Enterprise retail version and Visual Studio .NET 2003.
The Newsletter Team