How do you set focus on a textbox???? Seems like it should be easy, but...
Printable View
How do you set focus on a textbox???? Seems like it should be easy, but...
Make sure the form is visible before executing the method.VB Code:
Textbox1.Focus
is the form visible on the page load event?
Ive found occasional problems with setting focus in the form_load event.
To get around this I have processed the set focus from a timer that is enabled by the form_load event and dis-enabled after it processes once.
I use this event to set the focus to a textbox on the form load. It seems to work ok for me.
Code:Protected Overrides Sub OnActivated(ByVal e As System.EventArgs)
If (Me.txtDataFormat.Enabled = True) Then
'Set the focus to the txtDataFormat textbox otherwise
'set it to the txtDisplay textbox
Me.txtDataFormat.Focus()
Else
'Set the focus to the txtDisplay textbox
Me.txtDisplay.Focus()
End If
End Sub
txt1.focus()
its easier and faster
yeah, it is quicker but it doesn't work on the load of the page...you have to put txt1.focus in the code where you call the new page from...put it after frm1.show...
You could always set the text box to be the first item in the tab order, and then it'll have focus automatically when the form starts.
This only happens in VS.net 2002, it is fixed in vs.net 2003.
Took me a few days to discover !!
:sick: