TX Text Control ActiveX

Editing Marked Text Fields

Topic

In an editable TXTextControl, users change the text of an editable marked text field like any other text. At the edges of a field, though, it is not always clear whether the input position is inside or outside the field. Per-field editing attributes, set with the FieldEditAttr property, help users type in the right place and see where a field begins and ends.

Why the Edges of a Field Are Ambiguous

When the input position is directly in front of or behind a field, the next character can belong either to the field or to the text outside it. In normal editing mode, an inserted character takes the attributes of the character before it:

  • Text typed directly behind a field belongs to the field.
  • Text typed directly in front of a field belongs to the text in front of the field.

This is most noticeable when a marked text field is at the beginning or the end of the whole text. When a field ends the text, for example, CTRL+END moves the input position to the end of the text, which is also the end of the field, and everything typed there becomes part of the field.

Add a Second Input Position

The extended editing mode of FieldEditAttr adds a second input position at the beginning and at the end of a field: one inside the field and one outside it. Users switch between the two with the LEFT ARROW and RIGHT ARROW keys. In the example above, the user presses CTRL+END to reach the end of the text and then RIGHT ARROW, so that the next character does not belong to the field.

In code, FieldSetInputPos decides whether such a doubled input position is inside or outside the field.

Show Users Where a Field Is

Two further attributes help users find the right position:

  • Caret width. The caret gets a different width while the input position is inside the field.
  • Background. The complete text of the field is shown with a gray background while the input position is inside it.

Combine the Attributes

The attributes are set for each field on its own and can be combined in any way, so one TXTextControl can hold several kinds of marked text fields that behave differently. FieldEditAttr takes the field's identifier and the sum of the values you choose; changing one option does not affect the others. A newly inserted field has the value &H2 + &H8 + &H20 + &H80.

ValueEffect
&H1A second input position at the beginning and the end of the field.
&H2Normal editing at the beginning and the end of the field.
&H4A different caret width while the input position is inside the field.
&H8The normal text caret inside the field.
&H10The field's text with a gray background while the input position is inside it.
&H20The field's text with the standard control background while the input position is inside it.
&H40Normal double-click processing inside the field, which starts a word-wise selection; FieldDblClicked is suppressed.
&H80No normal double-click processing inside the field; FieldDblClicked is enabled.