Tips from ITKnowledge Exchange VB.Net - Control.SetFocus

Simple tasks like making a text box an area of focus must be revisited in VB.NET

Back in the "old days" of VB6, Me.txtBox.SetFocus would give the text box of interest the focus. I'm in the process of learning VB.Net and this simple task appears to have changed. For the moment I'm using VB 2005 Express, I don't know if this matters, but I don't see a method to set the focus in code.

Any thoughts?

Thanks,

Tony

Highlighted replies from CharlesJC and irarainey

Tony: In VB.Net(2003) object.Focus() does the trick. It should be the same if not very similar in VB2005. - CharlesJC

Tony: From the help file: The following code example sets focus to the specified Control, if it can receive focus.

Public Sub ControlSetFocus(control As Control)
' Set focus to the control, if it can receive focus.
If control.CanFocus Then
control.Focus()
End If
End Sub

-irarainey

For more go to ITKnowledge Exchange [Reg Req]

This was first published in April 2006

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close