Problem solve Get help with specific problems with your technologies, process and projects.

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?



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
End If
End Sub


For more go to ITKnowledge Exchange [Reg Req]

Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.