Automatically Change Font Color

jenvandiver

Registered User.
Local time
Today, 16:51
Joined
Oct 16, 2002
Messages
56
Is there a simple bit of code to make a text link on a form change color when a mouse pointer hovers over it? Or to change the color for good once clicked?

Thanks in advance for the help!
 
You can change the color in the MouseMove event.

i.e. There is a label on the form - Label1

In the mousemove event for Label1 you could put

Label1.forecolor = 255

This will change the Labels forecolor to red when the mouse is passed over it.

HTH,
Patrick
 
Thanks for your help. I tried your suggestion and it worked, however the color stays red ...it doesn't change back to the original color once the pointer has been removed. Also, the transparent label box surrounding the text flickers the color black when I move across the text (obviously noticeable). Is there an easy way to fix this?
 
Hi,
Firstly:
To change the color back to the original color when the Mouse is moved off the label you need to put corresponding code in the Form & detail mousemove events which change the label (back) to the color you want.

As for the label backcolor changing to black - this shouldnt happen & usually only happens if the label's backcolor was once set to black. Try resetting the backcolor to transparent or the color of the Form, if that doesnt work I would add a new label & see if the same problem occurs with that.

HTH,
Patrick.
 
To stop the flicker and return the colour:

Code:
Private Sub YourTextbox_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Text0.ForeColor <> 255 Then Text0.ForeColor = 255

End Sub

And on the Detail:

Code:
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Text0.ForeColor<> 0 Then Text0.ForeColor = 0
End Sub

Oh well, beaten to it.
 
Thanks for your responses. I tried the first suggestion, which worked as far as changing the color back, however I still have the flickering problem. Then I tried the last suggestion and I'm getting a run-time error (424). The debugger is highlighting the following part of code in the detail section.

If Text0.ForeColor <> 0 Then

I really appreciate all your help!
 
No, it's Label63. However, I've tried changing it and I'm getting the same highlight and error.
 
The Error number being raised is an "Object required" error,
must be to do with the spelling of your label name in code - is it definately correct?
 
You were right. I had to change both detail and label events to reference the correct label name. Before I had only fixed one of them.

I still have the flicker some but it's not as bad as before.

Thanks to both of you for all your help! That's why I love this site...:)
 
Ideally, you should give all objects that you use a proper name i.e since its a label prefix it with lbl and then its name (lblLabel, txtTextbox, cboCombobox, etc.)

It certainly makes it easier knowing what you are manipulating.
 

Users who are viewing this thread

Back
Top Bottom