how can I give focus to a textbox when the application starts?
where should i put the code 'textbox1.focus()?
thanks in advance
Printable View
how can I give focus to a textbox when the application starts?
where should i put the code 'textbox1.focus()?
thanks in advance
couldnt you just set the tabindex of it to 0?
you could also put textbox.focus () in form_load, couldnt you?
hi Mr.Polite
I placed some textboxes in a tabControl and made the tabindex of a textbox to 0.
but it didn't work. why?
it's working otherwise
Actually instead of SetFocus its now called Select() but setting the TabIndex to 0 should work.
but setting tabindex to 0 for a textbox which is placed in a tabcontrol is not getting focus. do u know why?
by the way
Instead of setfocus it's object.focus() in vb.net right?
i think select method is used to make a selection of the contents of a textbox. right?
but setting tabindex to 0 for a textbox which is placed in a tabcontrol is not getting focus. do u know why?
by the way
Instead of setfocus it's object.focus() in vb.net right?
i think select method is used to select a range of text in textbox. right?
errrrrrrrrm, here's a really dumb way to do it. Since no one else can think of the correct way:D :
VB Code:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged Dim firstCtrl, ctrl As Control For Each ctrl In TabControl1.SelectedTab.Controls If firstCtrl Is Nothing OrElse (ctrl.TabIndex < firstCtrl.TabIndex) Then firstCtrl = ctrl End If Next If Not firstCtrl Is Nothing Then firstCtrl.Focus() End Sub
ha ha! thank you very much Mr.Polite. But ....
should we really write that much code for that?
any way thanks
I dont think you need all that code. Just put
in the form load event.VB Code:
textBox1.Focus()
well, he wants the control to have the focus as the tabs are selected. I wrote the code like that so it would select the control with the lowest tabindex, everytime you select a different tab. This works even if you dont know the name of the control with the lowest tabindex in each tabQuote:
Originally posted by DevGrp
I dont think you need all that code. Just put
in the form load event.VB Code:
textBox1.Focus()
This is how to set focus
Private Sub Form_activate()
text1.setfocus
End Sub
text1 refering to which textbox you wish to focus on.
Do this in order of forms that appear and on those forms which
boxes you wish to start the sequence of tabs with.