Products Technologies Demo Docs Blog Support Company

Removing TextFields Completely when the User Removes Their Text

A TextField consists of text and additional data and can be handled like normal text. But there is an important difference: If you select a TextField and press {DELETE}, only the text is removed and the TextField is still active. In fact, the TextField is anchored to an input position, such as formatting information. An analogy: Open a new document within the shipped sample TX Words and click the bold button in the button bar. Type some characters like "Hello World!". Then select the words…

Removing TextFields Completely when the User Removes Their Text

A TextField consists of text and additional data and can be handled like normal text. But there is an important difference: If you select a TextField and press {DELETE}, only the text is removed and the TextField is still active. In fact, the TextField is anchored to an input position, such as formatting information.

An analogy: Open a new document within the shipped sample TX Words and click the bold button in the button bar. Type some characters like "Hello World!". Then select the words completely and remove the text by pressing the {DELETE} key. The text is removed. If you now start typing, the text is still bold.

The same is valid for the TextField. The field still exists at the input position before the first character of the field's text.

That implies that TX Text Control should not remove the field automatically. But word processing end-user applications like MS Word, help users to do their job easily. And you can assume, that in most cases, it is the user's intention to remove the field in such scenarios.

It has been always our philosophy to keep the API as flexible as possible, so that such requirements can be easily implemented. A very easy way to detect that the field's text has been removed is to trap the TextControl.TextFieldChanged event.

// [C#]
private bool bDeleteFields = true;

private void textControl1_TextFieldChanged(object sender,
    TXTextControl.TextFieldEventArgs e)
{
    if (bDeleteFields == false)
        return;

    if (e.TextField.Text == "")
        textControl1.TextFields.Remove(e.TextField);
}

In the event, the TextField will be removed completely, if the field's text is empty.

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.


ASP.NETWindows FormsWPF

Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub

This article gives a quick overview of the new repositories, their structure and our plans for the future.


ASP.NETJavaScriptDocument Editor

Detect Toggle Button Changes Using a MutationObserver

This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…


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…


Windows FormsSampleShortcuts

Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More

This article shows how to disable CTRL + MOUSE WHEEL, implement zooming with keyboard and reset the zoom factor to its default value.