Two Ways to Restart Numbered Lists in TX Text Control
In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two different approaches will be outlined.

In order to restart a list, you can simply set the restart numbering property for the list item to true. However, this can lead to confusion, because when return is pressed, this property is inherited to the next item and it restarts again. This can be overcome in different ways. The first strategy is to use Formatting
Using Formatting Styles to Format Lists
Let's say you want to start a document with several lists. For this you will create a style using the styles dialog. Create a new style, name it List and select the preferred Numbering in the format category. Make sure to choose Continue list for this style. Anytime you want to start a list, you can simply apply this style.
Now consider, you wish to separate the list in the middle. Then you will need a second list style. Create an new style, name it Restart and select the preferred numbering. Since you want to restart the list, choose Restart numbering this time. Also, and this is important, choose List as style for the following paragraph. This makes sure that the list continues when adding new list items. The style Restart can now be used any time a list should be restarted.
Restart Lists Using the TX Text Control API
If you prefer to implement this as part of your application to take this out of the hands of the end user, this approach is for you. A sample project can be found at the end of this article. The approach is simple: A global flag is used that indicates if the next inserted list should be continued. When the list at the current input position should be restarted, the flag is changed to true. The KeyUp event is used to check if the Enter key is pressed. If yes, the Restart
// global flag that indicates whether the next inserted list item
// should be continued
private bool restartFlag = false;
// restarts the numbering
private void button1_Click(object sender, EventArgs e)
{
textControl1.Selection.ListFormat.RestartNumbering = true;
restartFlag = true;
}
// continues the following paragraph (item), if the global flag is true
private void textControl1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode != Keys.Return || restartFlag == false) return;
if (textControl1.Selection.ListFormat.Type == TXTextControl.ListType.Numbered)
{
textControl1.Selection.ListFormat.RestartNumbering = false;
restartFlag = false;
}
}
Either way, restarting lists is very easy in Text Control and many ways lead to Rome. If you have further questions about these approaches, do not hesitate to contact us. Happy Coding!
Also See
This post references the following in the documentation:
- TXText
Control. Formatting Style Class - TXText
Control. List Format. Restart Numbering Property
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2019
- TX Text Control .NET for Windows Forms X19
Windows Forms
Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.
Related Post
Create a Table of Contents in Windows Forms using C#
This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.