What I have:
I have two group boxes each with a text box inside. A third text box is placed outside both of the group boxes.
Button 1 is the default accept button on form load.
What I need:
When button 1 is clicked (or enter key is pressed), I need button 2 to become the default accept button.
My problem:
Button 3 becomes the default accept button rather than button 2 in spite of my code.
My code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Me.AcceptButton = Button1
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("Button 1 pressed!")
GroupBox1.Enabled = False
GroupBox2.Enabled = True
Me.AcceptButton = Button2
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MessageBox.Show("Button 2 pressed!")
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Me.AcceptButton = Button1
End Sub
End Class
the problem is after you press button 1 button 3 gets focus.
you could fix it by adding code to focus to the button you need in the button 1 click event. "Button2.Focus()" etc..