Solved

vb.net button colors

Posted on 2007-04-02
4
369 Views
Last Modified: 2013-11-06
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?
0
Comment
Question by:dprundle
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
0
 
LVL 8

Expert Comment

by:Autoeforms
Comment Utility
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

greg
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
        WireUpButtons(Me)
    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
                WireUpButtons(ctl)
            End If
        Next
    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
0
 

Author Comment

by:dprundle
Comment Utility
Thanks Idle, you're amazing as always.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now