Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Simulate a traffic light with three small square text boxes placed vertically on

ID: 3544950 • Letter: S

Question


Simulate a traffic light with three small square text boxes placed vertically on a form. Initially, the bottom text box is solid green and the other text boxes are dark gray. When the Tab key is pressed, the middle text box turns yellow and the bottom text box turns dark gray. The next time Tab is pressed, the top text box turns red and the middle text box turns dark gray. Subsequent pressing of the Tab key cycles through the three colors. Hint: First place the bottom text box on the form, then the middle text box, and finally the top text box.

Explanation / Answer

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus

TextBox1.BackColor = Color.Green

TextBox3.BackColor = Color.DarkGray

End Sub


Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.GotFocus

TextBox2.BackColor = Color.Yellow

TextBox1.BackColor = Color.DarkGray

End Sub


Private Sub TextBox3_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.GotFocus

TextBox3.BackColor = Color.Red

TextBox2.BackColor = Color.DarkGray

End Sub