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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Form Label Font & Colour With Move Mouse

Status
Not open for further replies.

dominicdunmow

Technical User
Jul 28, 2004
125
CA
Hi,

I'd like the label on a form to change font and colour as the mouse pointer is moved over it.

I have got as far as going into Label "Properties" and using "On Mouse Move" but should I then use Code Builder? If so what code would I use to change the label text colour and font?

Thanks
 
Yes use the code builder in mouse move.. the use

assume label is called lblMine
font is Arial 10 and colour is 0 (black)

If Me.lblMine.Font = Arial Then
Me.lblMine.Font = Times New Roman
Me.lblMine.Forecolour = 255 '(Red)
Else
Me.lblMine.Font = Arial
Me.lblMine.Forecolour = 0
End if

Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 
or you can use a set of functions

Option Compare Database
Option Explicit
Dim strCtl As String
Dim blnSet As Boolean

Function fSetBold(sI As String)
If blnSet = False Then
If strCtl <> "" And strCtl <> Null Then
Me(strCtl).ForeColor = 0
Me(strCtl).FontBold = False
End If
If sI = "cmdExit" Then
Me(sI).ForeColor = vbRed
Else
Me(sI).ForeColor = vbBlue
End If
Me(sI).FontBold = True
strCtl = sI
blnSet = True
End If
End Function
Function fResetBold()
If blnSet = True Then
If strCtl <> "" Then
Me(strCtl).ForeColor = 0
Me(strCtl).FontBold = False
End If
blnSet = False
End If
End Function


Then to change the color and set the Font to Bold call the function from the MouseMove Event of the control and pass the name of the control to change

= fSetBold("NameOfControlToChange")


and to reset it back just call the the reset function on the Detail's Mouse Move event, or any adjacent control that you aren't going to change

No need to pass a control name for this since it uses the variable strCtl to capture the name.

= fResetBold()


This way all you have to do is add the call to the function (with the right control name) for each of the controls you want to change, and not have to add code for each one.

PaulF
 
Thanks for your replies.

Frank I tried yours first as I received it first but I get a Compile Error where Method or Data Member was not found,

The ".Font" on the first line is highlighted as being the problem.

Any ideas?
 
I've just checked - it should be Me.lblMine.FontName

Sorry..........

Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top