Change font color on Button

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
I would like to change the font color on my buttons when the button has focus, but have no clue where to set the color. As far as I can tell there is no focus event, I tried it on the enter event but nothing happened.
 
Edit: see post #7 for correct solution
 
Last edited:
I am actually doing this in C #, but I can convert it. When I use the enter event, I created one event to handle 5 buttons, only the button that I set the evnt handler on changes color.
 
I am actually doing this in C #, but I can convert it. When I use the enter event, I created one event to handle 5 buttons, only the button that I set the evnt handler on changes color.
Which is what you would normally want, correct?
 
No, what I was looking for was as the buttons are tabbed through or has focus or enters, on the Active Button the font will change to another color.
 
We're saying the same thing, make a new project, add 4 buttons to the form and paste this code in the code window:
VB.NET:
Public Class Form1

    Private m_HighLightColor As Color = Color.Blue

    Private Sub Button4_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Enter, Button3.Enter, Button2.Enter, Button1.Enter
        DirectCast(sender, Button).BackColor = m_HighLightColor
    End Sub

    Private Sub Button4_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Leave, Button3.Leave, Button2.Leave, Button1.Leave
        DirectCast(sender, Button).BackColor = SystemColors.Control
    End Sub
End Class
In this case I'm changing the backcolor, not the forecolor, just to nudge you in the right direction.
 
Out of a matter of interest Juggalo, why Enter and Leave as opposed to GotFocus and LostFocus?
 
A question along these lines of using the enter event. So all the controls with a backcolor, I set them to blue on enter and back to control on leave. I picked the first textbox on the form and double clicked in the Enter event in the properties.

Now I also have a text box that has to do a calculation on the enter event that is included with all the other controls, so the the user can see the data before moving on. Will one event cancel out the other.

I went into the designer and rewrote the enter event for the control doing the calculation and after running the application the event was gone.
 
You can have two subs handle a single event for a control and both will fire when the event is raised. As for what order they're fired in is another question and I don't know the answer.
 
Back
Top