Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SelectOnEntry in Textbox
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00855187
Message ID:
00855200
Views:
16
>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).
*** MouseDown() event
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.WhatsThisHelpID = INT(SECONDS())

***MouseUp() event
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton = 1
	DO CASE
		CASE ABS(INT(SECONDS()) - THIS.WHATSTHISHELPID ) > 1 && 1 sec delay
			* do nothing - leave the mouse pointer where it landed,
 allowing to position within the textbox
		CASE THIS.SELLENGTH = 0
			THIS.SELSTART = 0
			THIS.SELLENGTH = 1000 
		CASE THIS.SELLENGTH > 0
			* Leave the selection made as is
	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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform