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

How do I know when TAB key used in / from TextBox ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I want to know when the 'TAB' key has been used.
My focus is currently in a TextBox component.
I'm guessing I need to make use of one of 'KeyPress' / 'KeyUp' / 'KeyDown' but am failing to find code that gives me the required result.
Any help would be greatly appreciated.
Thanks in advance
Steve
 
add a KeyUp event handler and add the code within the braces so it looks like this:

private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == (int)Keys.Tab)
MessageBox.Show("tab pressed");
}

Steve
 
Thanks so far.
It almost works for me - however the action seems to be triggered when I go into the TextBox component. I want to be able to determine whether my TextBox was left via means of the TAB key being used.
How can I do this ?
I hope that you can fill in the blanks for me .... :)
Thanks in advance
Steve
 
I'm still perplexed by this. :(
The test application is no more complicated than the following :
Drop a tabControl on a form, and add two tab pages to it. Put a textBox in each tabPage.
I want the user to move to the textBox in the second tabPage when they use the TAB key (and leave) the textBox in the first tabPage.
This should be simple but I can't see it for trying.
Can someone give me the code for this (it's got to be!) simple concept ?
Thanks in advance
 
I'm not a GUI guy, but try simplifying it first -- try going to another textbox or other control on the same tab. Once you've gotten that working, then move the target textbox to another tab.

I suspect your problem may be forcing the second tab to be visible, as you probably can't set focus to a control that isn't being shown to the user.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top