vb.net button colors

When making a button in VB.Net in visual studio 2005, how do I make the button so that the active button (button that is currently tabbed to) has a different background color than the rest of the buttons?
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
To "wire up" all the buttons on a Form:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Private Sub WireUpButtons(ByVal container As Control)
        For Each ctl As Control In container.Controls
            If TypeOf ctl Is Button Then
                AddHandler ctl.GotFocus, AddressOf Button_GotFocus
                AddHandler ctl.LostFocus, AddressOf Button_LostFocus
            ElseIf ctl.HasChildren Then
            End If
    End Sub

    Private Sub Button_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.BackColor = Color.Green
    End Sub

    Private Sub Button_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.BackColor = System.Drawing.SystemColors.Control
    End Sub

End Class
Mike TomlinsonMiddle School Assistant TeacherCommented:
have you tried changing the .backcolor property in the gotfocus event.
i would remember the original color in private variable so you can set it back
in the lostfocus event.

good luck

dprundleAuthor Commented:
Thanks Idle, you're amazing as always.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.