Products Technologies Demo Docs Blog Support Company

Casting TextField Derivatives

TX Text Control's PageNumberField inherits from TextField, so TextFieldClicked fires when a user clicks a page number in a header or footer. Casting the returned TextField to PageNumberField grants access to derived properties, allowing the field to be removed from the header collection.

Casting TextField Derivatives

I just saw an interesting support request by reviewing the solved cases in our support department. A customer wanted to know how to remove a page number field in a header or footer by clicking on it.

From our documentation:

The PageNumberField class represents a field in a header or footer of a Text Control document that automatically displays the current page number. The class inherits all properties and methods from the TextField class.

Due to the fact that the PageNumberField is derived from the TextField base class, it's events can be used as well. The TextFieldClicked event returns the clicked TextField.

If the user clicks on a PageNumberField, this event is fired as well. To access the properties of the PageNumberField, you need to cast the returned field to the derived type:

private void textControl1_TextFieldClicked(object sender, TXTextControl.TextFieldEventArgs e)
{
    TXTextControl.PageNumberField myField = (TXTextControl.PageNumberField)e.TextField;
    textControl1.Sections.GetItem().HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Header).PageNumberFields.Remove(myField);
}

This approach is possible with all derived TextField types like ApplicationField, DocumentTarget or DocumentLink.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsWPF.NET

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.


Windows FormsList.NET

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…


.NETSample

Paste Special: The Easy Way to Implement

TX Text Control version 15.0 introduced a ClipboardFormat parameter on the Paste method, enabling native Paste Special functionality. The GetClipboardFormats method returns all available clipboard…


.NETSampleSections

How to Remove All Section Breaks in a Document?

TX Text Control 15.0 adds per-section page column support alongside existing section breaks. To remove all section breaks programmatically, iterate through SectionCollection using…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

Batch printing multiple documents as a single print job using TX Text Control relies on a .NET PrintDocument with PrintPage and QueryPageSettings events. Each page is rendered individually via the…

Share on this blog post on: