Stylesheet Selection

TX Text Control X19 is able to generate table of contents automatically based on used styles in a document. In the ribbon tab References, the styles, that should be included in the table of contents, can be selected:

TOC in TX Text Control

In the Table of Contents dialog, the minimum and maximum structure levels can be defined in order to add a newly generated table of contents at the current input position.

TOC in TX Text Control

Generate Stylesheets

Now consider an unstructured document without used stylesheets. The user would have to create and apply styles first, before a table of contents can be generated. This sample shows how to convert an existing formatting to a style and how to apply this style to all similar paragraphs with the same layout.

The following screenshot shows a document without any stylesheets. But visually, the headings (in bold) are formatted in a different way:

TOC in TX Text Control

The following extension method converts the formatting at the current input position into a ParagraphStyle TX Text Control .NET for Windows Forms
TXTextControl Namespace
ParagraphStyle Class
The ParagraphStyle class defines a formatting style for paragraphs.
and returns the newly created style name:

Loading...

The next extension method applies this style to all paragraphs with the same formatting:

Loading...

In the sample, a new button is added to the References tab that calls the extension methods:

TOC in TX Text Control

Loading...

Create the Table of Contents

Now, the new style can be selected as a structure level:

TOC in TX Text Control

And after that, a table of contens can be added based on the newly created styles:

TOC in TX Text Control

Feel free to download the sample from our GitHub repository and test this on your own.