Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Restarting a numbered list

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C# .NET
Version:1.0
Released:August 08, 2007
Last modified:January 11, 2008
Requirements:TX Text Control .NET with Visual Studio 2005
Download code:tx_restart_lists.zip Download [13.38 KB, ZIP]

TX Text Control provides fully featured dialog boxes to set almost all formatting options. Using the ListFormatDialog, it is possible to adjust all formatting attributes of bullets and numbered lists. Additionally, it allows the user to restart a numbered list, so that the current item starts with the default value.

Sometimes, it is necessary to provide a button in the button bar that allows the user to restart a list. This saves the user from having to open the respective dialog box. As always in TX Text Control, all settings of the dialog boxes are accessible from within the API of TX Text Control.

To restart a list, the ListFormat.RestartNumbering property has been implemented. If this property is set to true, the current item will be restarted with the default value.

  1. textControl1.Selection.ListFormat.RestartNumbering = true;

If the user inserts another item by pressing return, the following item inherits the RestartNumbering value. In other words, the new item is restarted as well. This can be avoided by setting the RestartNumbering property to false.

This samples uses a global flag that indicates whether the new list item should be continued or not.

  1. private bool restartFlag = false;
  2.  
  3. private void button1_Click(object sender, EventArgs e)
  4. {
  5. textControl1.Selection.ListFormat.RestartNumbering = true;
  6. restartFlag = true;
  7. }

The KeyUp event is used to trap the return key and to continue the newly inserted list item.

  1. private void textControl1_KeyUp(object sender, KeyEventArgs e)
  2. {
  3. if (e.KeyCode != Keys.Return || restartFlag == false) return;
  4.  
  5. if (textControl1.Selection.ListFormat.Type == TXTextControl.ListType.Numbered)
  6. {
  7. textControl1.Selection.ListFormat.RestartNumbering = false;
  8. restartFlag = false;
  9. }
  10. }

To use the downloadable version of this sample you need TX Text Control .NET 13.0 trial version or better.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place