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.