?
Solved

vb.net button colors

Posted on 2007-04-02
4
Medium Priority
?
405 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 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.
Suggested Courses

719 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