Solved

vb.net button colors

Posted on 2007-04-02
4
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18837903
0
 
LVL 8

Expert Comment

by:Autoeforms
ID: 18837905
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 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18837940
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
ID: 18838941
Thanks Idle, you're amazing as always.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

738 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