Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Font Colours when mose over 1

Status
Not open for further replies.

Adric

Programmer
Jun 25, 2001
24
US
How do I make the font color change when the mouse is over the text i want to have change
 
Here you would need to use my FAQ, but instead loading a picture for the button, you would need to change the text property (of the label or other control):

lblButton.ForeColor = vbRed (or what other color you want it to be).

"MouseOver" combined with "MouseOff" events (like in HTML) are complicated in VB.

I hope this helps? Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
I know nothing about modules so could you explain it to me?
 
Oh, sure:

A module is like a form, just that it doesn't have any visual representation within your project. Think of a module as a package, where you store functions and subs that can be used in the entire project.

To create a module, click on Project (in the menu), then Add Module. To insert your code int the module, simply double click on the module in your Project Group window.

If your familiar with C++, think of a module as a .cpp file containing methods.

Modules are most often used to store functions and procedures that get called repeatedly from various forms, thus reducing the amount of code in your project.

Hope this helps :) Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
So If I did want to change the picture do I have to pass variables to the module and if the module is, say xxx, I would say xxx(yyy,zzz)?
 
Okay if you have a label on a form, (named label1) here this would work)

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.ForeColor = vbYellow
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.ForeColor = vbBlue
End Sub

 
When using a module, you don't actuallyt call the module. Rather, you called the functions that the module contains.
In the module you write out the functions the same way you would in a form.

Say your module contained the sub:

Public MySub(Change as String)
blabla
End Sub

you would call it from your form like this:

Call MySub("blabla")

Thats just an example. Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
Those colors will stay when the mouse moves out of the box (no mouseleave event) unless you use a mousemove for the surrounding form or frame to reset them. Fastest is to use a form level object variable to hold NOTHING or the last object for which color changed. If the controls have different default colors then you will have to save and restore the forecolor also.
 
John is right, VB does not hove MouseOver and MouseOff events - I was merely referring to HTML (hope I didn't confuse you there).

The only proble with using a form-level MouseMove event is that you can't have the adjacent areas of the button be covered by a different object, otherwise the Form1_MouseMove() event won't register (as far as I'm aware of anyway).
Thats why I went the somewhat troublesome rout using API call and a timer. (Note: when using a timer, be sure to set its interval to something smaller or equal to 100, otherwise it might use up too much system resources.)

However, if you have adjacent areas around the button displaying only the form, then use John's code, you'll save yourself some work. :) Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top