Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor position in a TextBox 2

Status
Not open for further replies.

florindaniel

Programmer
Dec 4, 2009
120
RO
Hello,

I have a textbox I want to type in numbers in '999999' format.
SelectOnEntry=.T. but if the user clicks inside of the text box to get access to it
and type in data, he may click somewhere inside the editable area, let's say two places
from right to left and then he can only type in two digits.

If the control gets it's focus via TAB it is OK, since the whole text is selected and typing
begins on the left.

The problem appears, as I said, only when the user click inside the textbox and does that near
the left edge.

I tried to trick this issue with SelStart, SelText, SelLenght but it didn't work.

Any ideas?

Thank you,
Daniel
 
Gotfocus:
If this.SelectOnEntry
this.SelStart = 0
this.SelLength = 1000
Endif
 
Nope, it doesn't work :(

I have this numeric text box with '999999' format.
At run-time it shows '0' and if I click JUST BEFORE or JUST AFTER the 0
it will only allow one char to enter. If I click inside the textbos somewhere on
the left side it will work as intended.

I must say I have no control over the position the user will click inside the textbox
and it has happened the scenario above.
 
Try putting this in the GotFocus event of the text box:
Code:
KEYBOARD "{HOME}"

"HOME" is enclosed in curly brackets. Hope this helps.


kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
Well, how about doing what Tore Bleken suggests in the Click event? Haven't tested it, but it should work.
Another thing you could try is stop click behaviour by putting nodefault into click event, and perhaps explicitly call the base textbox gotfocus behaviour by textbox::gotfocus().

Bye, Olaf.
 
Both solution I suggest, I just tried them. And both disable you from actively selecting the portion of the number you want to change. So actually I prefer the way Foxpro does it, it gives more control what to edit. The simple way to select all is double click instead of single click, which also is a standard for selecting whole words in word processing, even in notepad. So indeed those users complaining about needing to click into the leftmost poriton of a textbox should just be told they simply don't know what a double click does by default, not only in a VFP textbox.

Bye, Olaf.
 
Finally here's a compromise still allowing to select something in the textbox via mouse:

Code:
*in Textbox.Click put:
If This.SelectOnEntry And This.SelLength=0
   NoDefault
   Textbox::GotFocus()
Endif

You could put this in a base textbox class and setting SelectOnEntry=.T.would then trigger this behaviour over standard behaviour, which surely also is desirable. Otherwise you could only check for This.Sellength=0 or do it always, but I really would hate an application restricting my cpabilities.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top