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