Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 20, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Return Focus After Button Click

Here's an easy way to return the focus to a control after the user clicks on a button on the screen. If you use the keyboard, you can save time this way by not having to tab back to where you were. First, create a module variable of type Control, and call it mCtl. Next, in the GotFocus event of each input control, set mCtl equal to the control that got the focus. When you want to return the focus after the Click event, execute the SetFocus method of mCtl:

Private mCtl As Control

Private Sub Command1_Click()
	' perform normal button routine here, then
	' return focus to previous control.
	On Error Resume Next
End Sub

Private Sub Text1_GotFocus()
	Set mCtl = Text1
End Sub

Private Sub Text2_GotFocus()
	Set mCtl = Text2
End Sub
Ed Ordorica
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date