TX Text Control .NET for Windows Forms Documentation

Page Numbers

In a header or footer, accessible through the HeaderFooter class, special placeholders for page numbers can be inserted. Such a placeholder is defined through the PageNumberField class, also derived from the TextField class. Using such a field, a header or footer automatically shows the current page number on every page.

Page number fields inherit the editing features of the TextField class and have additionally a NumberFormat and a StartNumber property. The NumberFormat property specifies the kind of numbers used to display the page numbers. Possible values are Arabic numbers, small and large Roman numbers, letters and capital letters. The StartNumber property defines the starting page number for the first page.

The following code adds a header to the current document. After insertion, the header receives a text and a page number field:

[C#] HeaderFooterCollection hfc = textControl1.HeadersAndFooters; hfc.Styles = HeaderFooterStyles.ActivateClick | HeaderFooterStyles.SingleFrame; hfc.Add(HeaderFooterType.Header); HeaderFooter h = hfc.GetItem(HeaderFooterType.Header); if (h != null) { h.Selection.Text = "Page "; h.Selection.Start = 5; h.Selection.Length = 0; PageNumberField p = new PageNumberField(1, NumberFormat.RomanNumbers); p.Editable = false; p.DoubledInputPosition = true; h.PageNumberFields.Add(p); }
[Visual Basic] Dim hfc As HeaderFooterCollection = TextControl1.HeadersAndFooters hfc.Styles = HeaderFooterStyles.ActivateClick + HeaderFooterStyles.SingleFrame hfc.Add(HeaderFooterType.Header) Dim h As HeaderFooter = hfc.GetItem(HeaderFooterType.Header) If Not h Is Nothing Then h.Selection.Text = "Page " h.Selection.Start = 5 h.Selection.Length = 0 Dim p As New PageNumberField(1, NumberFormat.RomanNumbers) p.Editable = False p.DoubledInputPosition = True h.PageNumberFields.Add(p) End If

After the header has been inserted in the document, it receives the text Page with a space at the end. Because a header has no Text property, this is done by replacing the text of the current text selection using the Selection class. Initially, a newly inserted header has no text, therefore the initial text selection has a length of zero so that the new text is inserted.

Afterwards, the current text input position is set to the end of the text where the page number field is inserted. This field is set to not editable, so that an end-user cannot change its current text. To enable text insertion right of the page number, a second input position is needed. This can be reached by pressing the Right Arrow key at the text end.

 
 
 

Products

Support

Downloads

Corporate

Buy Now