This message contains graphics. If you do not see the graphics: Graphic Version.
Building a document navigation index

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 ComboBox1.Items.Add(myStyles.Name) End If Next

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 TreeView1.Nodes.Add(nodeString) End If Next

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.

Best regards

The Newsletter Team

Text Control GmbH respects your online time and privacy. We only send this newsletter to TX Text Control customers and people who have signed up to receive it. However, if you would prefer not to receive future issues of the newsletter, you may unsubscribe at any time. If you received this newsletter forwarded from a colleague or friend, you may wish to subscribe directly.

Sent to: N/A.

Imprint | Unsubscribe | Subscribe

© 2020 Text Control GmbH. All Rights Reserved.