Text Selection
From Xojo Documentation
Contents
A text selection is text that is highlighted, either by the user or by using the appropriate properties of the control.
You can manage text selection in the Desktop Text Field and Text Area controls using several properties and methods.
The SelChange event is called when the user selects text in the control.
You can use the SelectAll method in your code to select all the text in a control.
These properties can be used to view or change the selected text:
- SelLength
- The number of characters currently selected. You can change the selected text by changing this number. Setting this value to 0 (zero) will position the insertion point based on the value in the SelStart property rather than selecting any text.
- SelStart
- The number of the character just before the selected text. For example, if the fifth character in a Text Field was selected, this property would be 4. Setting this value to 0 (zero) will start the selection at the first character of the Text Field.
- SelText
- A string containing all of the selected text. Changing this value will replace the selected text with the SelText value. If no text is selected, the SelText value will be inserted at the insertion point (the value in SelStart).
Usage
Assume you have a Text Area with the text "A quick brown fox."
This code selects "quick":
TextArea1.SelLength = 5
This code changes "quick" to "speedy":
TextArea1.SelLength = 5
TextArea1.SelText = "speedy"
This code in the SelChange event change text that the user selects to all uppercase:
See Also
UserGuide:Framework, UserGuide:Desktop Text Field, UserGuide:Desktop Text Area topics