UserGuide

Text Selection

From Xojo Documentation

Revision as of 03:00, 12 February 2021 by Gperlman (talk | contribs)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

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.

TextField1.SelectAll

These properties can be used to view or change the selected text:

Name Description
SelectionLength 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 SelectionStart property rather than selecting any text.
SelectionStart 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.
SelectionText A string containing all of the selected text. Changing this value will replace the selected text with the SelectionText value. If no text is selected, the SelectionText value will be inserted at the insertion point (the value in SelectionStart).

Usage

Assume you have a Text Area with the text "A quick brown fox."

This code selects "quick":

TextArea1.SelectionStart = 2
TextArea1.SelectionLength = 5

This code changes "quick" to "speedy":

TextArea1.SelectionStart = 2
TextArea1.SelectionLength = 5
TextArea1.SelectedText = "speedy"

This code in the SelChange event change text that the user selects to all uppercase:

Me.SelectedText = Uppercase(Me.SelectedText)

See Also

UserGuide:Desktop Text Field, UserGuide:Desktop Text Area topics