Products Technologies Demo Docs Blog Support Company

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…

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

In an older sample, I showed how to implement a paste special functionality by accessing the clipboard directly using .NET functionality. In version 15.0, we implemented this functionality…


.NETSampleSections

How to Remove All Section Breaks in a Document?

With version 14.0, we introduced document section breaks that allow you to have different page formats in the same document. Version 15.0 implements page columns that can be adjusted section-wise.…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our…