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

changing labels forcore and backcolor

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hey Guys

I don't have much experience with module but I created a form and I would like to have the labels in the form to have thier forecolor =vbred and their backcolor vbyellow when my mouse moves over it and when it is not moved I would like it to have forecolor=vbwhite and backcolor=vbblue

Can this be done and if so can you help me out.

Thanks a lot
or you can maybe paste some links to websites where I could learn more about creating module. Thank You
 
If you use the MouseMove event of either a "freestanding" label (one not connected to a textbox) or the textbox that has a connected label, you can set the label's ForeColor property.

To change it back to the orginal vbBlack (or other color), you will need to create a option group (with no options) or rectangle as big as the form, background color = form's, and use its MouseMove event to change the label's ForeColor back.

Example:

Form1 is filled with white has 4 controls:
- Frame0 is an option group filled with white that consumes the entire form. (Format menu, Send to Back)
- Label0 is an independent label on top of Frame0 filled with white.
- Text1 is a textbox on top of Frame0.
- Label0 is a Text1-connected label on top of Frame0 filled with white.

Form Event Code: (click on the form/control, View menu, Properties, Event tab, click in On
MouseMove, click the dropdown, select [Event Procedure], and click the 3 dot button to the
right.
Code:
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.Caption = "Form1:" & X & "/" & Y
    Me!Label0.ForeColor = vbBlack
    Me!Label0.BackColor = vbWhite
    Me!Label1.ForeColor = vbBlack
    Me!Label1.BackColor = vbWhite
End Sub

Private Sub Frame0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.Caption = "Frame0:" & X & "/" & Y
    Me!Label0.ForeColor = vbBlack
    Me!Label0.BackColor = vbWhite
    Me!Label1.ForeColor = vbBlack
    Me!Label1.BackColor = vbWhite
End Sub

Private Sub Label0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.Caption = "Label0:" & X & "/" & Y
    Me!Label0.ForeColor = vbWhite
    Me!Label0.BackColor = vbBlack
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.Caption = "Label1:" & X & "/" & Y
    If X < 0 Then 
        Me!Label1.ForeColor = vbRed
        Me!Label1.BackColor = vbYellow
    End If
End Sub

Save and run the form. The labels, frame and form will show the X/Y coordinates in the form's title bar (caption) and the label's color should change. Jim Kraxberger
Developing Access solutions since 1995
jkraxberger@scp4me.com
 
at51178:

Here's what I do to simulate mouse rollovers on lables, but there's probably a better way:

For the label you want to change, on the mouse move event, enter the following:

Code:
Private Sub Label33_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Me.Label33
    .BackColor = vbRed
    .ForeColor = vbWhite
End With

End Sub
Then, on the form's mouse move event, enter the reverse:

Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Me.Label33
    .BackColor = vbWhite
    .ForeColor = vbRed
End With
End Sub

This simulates the mouseover effect on websites, et cetera.

There's probably a better way, but this one works great for me!

Walks With Sky
 
First off thanks for taking the time to respond to my post
I do appreciate it

I have used similar codes to do this already but I have about 50 labels in my form and I do not want to write all that code I was looking for a way to write a module where I could tell the computer that
if the mouse is over anylabel to change the forecolor to vbred and the backcolor to vbyellow and then when it is not over it to change it back to the way it was.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top