combobox steals focus

didgydont

Active member
Joined
Mar 2, 2009
Messages
37
Programming Experience
Beginner
hi all
i have 4 forms i have made a password form(form4) wich i started when form 1 loads
VB.NET:
If My.Settings.Userpassenable = Enabled Then
            Form4.ShowDialog()
        End If
i have set on form 4 load
maskedtextbox1.focse()
but the combo box on form 1 keep taking focus
i found that out by setting Form4.ShowDialog() to Form4.Show() on form 1 any ideas ?
thank you
 
My friend in order to set the focus to a control you have to make it like this:

VB.NET:
Me.ActiveControl = maskedtextbox1

Have fun.
 
maskedtextbox1.select will place the caret in the box and waiting for user input.
 
The select method is for selecting the contents of the control. Of course the select method will activate the control but this is not the right way to activate it.
 
thank you both very much
i went with "Me.ActiveControl = maskedtextbox1"
but "maskedtextbox1.select" will be a good thing to remember
thank you both again
 
The select method is for selecting the contents of the control. Of course the select method will activate the control but this is not the right way to activate it.
That is not correct. Select with no parameters is inherited from the control class and simply sets focus to the control. It's functionally equivalent to setting the ActiveControl property. Select with two Integer parameters is for selecting text within the control and it will NOT affect focus at all.

MaskedTextBox.Select Method (System.Windows.Forms)

As for the original question, there's probably no need to explicitly set focus to any particular control. When a form is displayed for the first time it will focus the first control in the tab order. If you want your MaskedTextBox to initially have focus then you should simply make it first in the tab order. This may not be possible in a complex layout but for simple forms it's the best way to go.
 
The tab order is an other good idea that you suggested. Anyway, I think that we helped didgydont to solve his problem.

Have a nice day both of you.
 
Back
Top