Solved

vb.net button colors

Posted on 2007-04-02
4
400 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

630 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