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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set focus to two text box only? 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
Hi everyone... i have ten texboxes in a form, but i want text1 and text2 only to be on focused everytime a user presses Tab key from the keyaboard. When the cursor is in text1 and when tab is pressed the cursor goes to text2, and when tab is pressed again, the cursor should goes back to text1. thanks in advance...
 
Hi Mandy,

Just disable TextBoxes 3 to 10 or add in the LostFocus event of YourTextBox2Name this piece of code "ThisForm.YourTextBox1Name.SetFocus" (without the quotes)

hth

MarK
 
Alternatively, set the other controls' TabStop property to .F.

This will prevent them receiving focus via the keyboard (in particular, the Tab key), but you will still be able to click on them with the mouse.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yet another alternative is to disable the other textboxes, i.e. set their Enabled property to .F.

Then they can't even get focused with the mouse. When that is done, you could also use labels instead of disabled textboxes, because all the user can use them for is reading their value. The only reason for using textboxes that are not able to be activated controls users can also enter into is to display information, isn't it? I'd be careful using disabled textboxes for that purpose, as values too long to read are also not scrollable, whereas a lable can automatically adjust its size and also allows wordwrap. The only disadvantage is you can't set a label caption with a controlsource from data and would need to set the label captions by code.

I wonder about the reasoning beacuse depending on what's in the other textboxes removing the capability to tab to them can be a bad choice. A user could also simply use SHIFT+TAB in text2 to go back to text1. It's even apparent from the keyboard icon on the tab key, if it's a keybboard not simply having "TAB" written on that key, but having the symbol of a left arrow over a right arrow. The left arrow is what you get with SHIFT+the key, just like all the symbols on top of the digit keys in the top row of the main keyboard block (ignoring the F key row).

So, in short, just make users aware they can go forth AND back with the TAB key, esepcially if there is no reason to keep users away from all the other textboxes.

Chriss
 
Thank you so much mjmkrsr and Mike... It worked!!! Godbless....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top