>Hello,
>
>I tried to get the following done, but it does not work:
>When the user clicks into a textbox, the text should be selected, exactly as when tabbing into the textbox and the property .SelectOnEntry = .T.
>
>There is a FAQ by Evan Delay, 7867, that suggests to put DODEFAULT() into the GotFocus() event of the textbox, but that does not show results.
>
>I tried the following in the GotFocus() event:
>THIS.SelStart=0
>THIS.SelLength=LEN(ALLTRIM(TRANSFORM(THIS.VALUE)))
>This would work relatively fine, except when the value is longer than the textbox shows, which results in shifting the entire selected text to the left. That is confusing for the user.
>
>Is there a way to accomplish this?
>Thanks for your help in advance!
I wrote about this exact problem in
Re: How to select textbox when mousing in Thread #
846750 Message #
846833 I will just repeat it here:
< SNIP > *******************************************************************
The extended features of the Left Mouse click :)
1. One short click selects the whole textbox value
2. You still can do the manual text selection in the box
3. If you click and hold the mouse for more than one second, the cursor will stay where you clicked and you still can do the normal editing.
4. As a bonus :) DoubleClick selects the existing text and the trailing spaces (but not the leading spaces (if any).
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.WhatsThisHelpID = INT(SECONDS())
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton = 1
DO CASE
CASE ABS(INT(SECONDS()) - THIS.WHATSTHISHELPID ) > 1
allowing to position within the textbox
CASE THIS.SELLENGTH = 0
THIS.SELSTART = 0
THIS.SELLENGTH = 1000
CASE THIS.SELLENGTH > 0
ENDCASE
ENDIF
I employed the rarely used WhatsThisHelpID property to hold the SECONDS() value
just for this example. Of course, you can use a custom property for that.
I used THIS.SELLENGTH = 1000 for the whole text selection to avoid
unnecessary function calls.
Using THIS.SELSTART = 0 and THIS.SELLENGTH = LEN(ALLTRIM(this.Value)) or THIS.SELLENGTH = LEN(ALLTRIM(this.Text)) is not reliable
if the textbox value has the leading spaces.
< END SNIP > ****************************************************************
P.S. Of course, you can just throw away the extra features if you don't need them.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro
"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison