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

Capturing Tab key

Status
Not open for further replies.

rjoubert

Programmer
Oct 2, 2003
1,843
US
Using PGoRule's code from I have been able to capture the Tab key. Now, I want to be able to find out which textbox control was active when the tab key was pressed. I tried the following code...

Code:
Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
   MyBase.ProcessTabKey(forward)

   If Me.ActiveControl.Name = "Textbox3" Then
      MessageBox.Show("GOT IT!!!")
   End If

End Function

But it's not evaluating Me.ActiveControl until AFTER the tab has moved to the next field. So, upon hitting the tab key on Textbox2, the message appears. I want it to appear when I hit the Tab key on Textbox3. Any suggestions?
 
Nevermind...I found a workaround. I created a textbox control that "blends in" to the background, so it appears to be invisible (setting visible to false seems to prevent it from accepting the tab), and I'm checking for this textbox as the activecontrol.
 
i hate to be obtuse here, but couldnt you just process your message handling on the got/lost focus event? wouldnt that take care of if the user clicked into or out of the box?

-The answer to your problem may not be the answer to your question.
 
try something like this:
Code:
	Dim HadFocus As String

	Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus, TextBox2.LostFocus, TextBox3.LostFocus, TextBox4.LostFocus, TextBox5.LostFocus
		Dim tb As TextBox = sender
		HadFocus = tb.Name
	End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top