I just fished two little TextField code snippets out of our source code pool that is being filled during the daily support work.

1. Navigating to the next TextField

This snippet shows how to set the input position to the next TextField, if the current input position is inside of another TextField and the user presses the TAB key.

private void textControl1_KeyPress(object sender, KeyPressEventArgs e)
{
    TXTextControl.TextField curField = textControl1.TextFields.GetItem();
    if (curField == null || e.KeyChar != 9) return;

    bool bIsFieldMatch = false;

    foreach (TXTextControl.TextField field in textControl1.TextFields)
    {
        if (bIsFieldMatch == true)
        {
            textControl1.InputPosition = new TXTextControl.InputPosition(
                field.Start - 1,
                TXTextControl.TextFieldPosition.InsideTextField);

            break;
        }

        if (field.Start == curField.Start)
            bIsFieldMatch = true;
    }

    e.Handled = true;
}

2. Ensure that the input position is always inside a TextField

You might know the doubled input position of TextFields that enables an input position inside and outside of a TextField. From our documentation:

If a marked text field is fully editable, the two text input positions at the beginning and the end of a marked text field have a special meaning. If an end-user inserts text at one of these positions, it is not unique whether or not the newly inserted text belongs to the field. To solve this problem, the TextField class offers the DoubledInputPosition property. This implements a second input position, which the end-user can reach with the Left Arrow and Right Arrow keyboard keys.

If the user is not used to this doubled input position, it might be confusing, if the user is setting the caret to the beginning of a TextField, but the text he is typing is not inside the field. The following snippet ensures that the input position is always inside of the TextField, if the user sets the caret to the character position before the field:

private void textControl1_InputPositionChanged(object sender, EventArgs e)
{
    foreach (TXTextControl.TextField field in textControl1.TextFields)
    {
        if (textControl1.Selection.Start == field.Start - 1)
        {
            textControl1.InputPosition = new TXTextControl.InputPosition(
                textControl1.Selection.Start,
                TXTextControl.TextFieldPosition.InsideTextField);

            break;
        }
    }
}

Do you have similar requirements and you are not sure how to solve it? Request such snippets by opening a support case here:

Open TX Text Control Support Case