This is baffling me. I have a Windows Form with a TextBox, 2 RadioButtons, an OK Button & a Cancel Button. I was mucking around with Tabbing, but I have now removed it, so TextBox1 is set to TabIndex=1 & TabStop=True, all the other fields are set to TabIndex=0 & TabStop=False.
To get to this Form,I execute the following code :
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ChooseLeague.SelectedIndexChanged
If ChooseLeague.SelectedIndex = 0 Then
Me.Hide()
MaintainDatabaseAddLeague.RadioButton1.Checked = False
MaintainDatabaseAddLeague.RadioButton2.Checked = False
MaintainDatabaseAddLeague.TextBox1.Text = ""
MaintainDatabaseAddLeague.TextBox1.Focus()
MaintainDatabaseAddLeague.Show()
End If
End Sub
The Form opens and the cursor is blinking in the TextBox as required. However, if I cancel from the Form & then go back into it via the same method, the cursor is NOT in the TextBox and the Cancel Button is highlighted / has Focus.
Why is this, any ideas ?!?
Since you are hiding and showing the form, it is showing the last focused control. The focus call doesn’t work until after the form is visible.
Try switching it around and use the
Selectmethod.