How to highlight all the text in a control when it gets focus by a mouse click

Top  Previous  Next

When you tab to an entry control with the tab key, the entire entry field plus any existing text, is highlighted. Then, when you begin typing, the highlighted text is immediately overwritten. However, when you select an entry control with the mouse, you get an I-beam insertion point somewhere inside the entry field, and existing text is not highlighted.

To force a mouse selection to behave like the tab key, add MouseLeft to the list of Alert keys for the control, then embed some code to "select" the entire field when the mouse is CLICKED:

1.

From the Window Designer, RIGHT-CLICK the control and choose Alert from the popup menu.

2.

From the Alert Keys dialog, press the Add button.

3.

From the Input Key dialog, CLICK on Left Button in the Mouse group.

4.

Press OK twice to return to the Window Designer.

5.

From the Window Designer, RIGHT-CLICK the control and choose Embeds from the popup menu.

6.

Add the following code to the EVENT:AlertKey embed point for the control:

 

IF KEYCODE() = MouseLeft

 SELECT(?,LEN(?{PROP:ScreenText}))

 ?{PROP:SelStart} = 1

 ?{PROP:SelEnd} = LEN(?{PROP:ScreenText})

END