| |

VerySource

 Forgot password?
 Register
Search
View: 846|Reply: 3

How to make the label change the background color when the mouse moves to a label and when the mouse moves away, the lab

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-16 22:30:01
| Show all posts |Read mode
I've tried adjusting the color of the label's MouseMove Event event. When the mouse moves to a label, it doesn't work at all. Is there a better way?
Private Sub LbMain_MouseMove (Index As Integer, Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim i As Integer, iLeft As Long, iRight As Long, iTop As Long, iBottom As Long
 i = Index
 iLeft = LbMain (i) .Left
 iRight = LbMain (i) .Left + LbMain (i) .Width
 iTop = LbMain (i) .Top
 iBottom = LbMain (i) .Height + LbMain (i) .Top
 If x> iLeft And x <iRight And Y> iTop And Y <iBottom Then
  LbMain (i) .ForeColor = vbBlue
 Else
  LbMain (i) .ForeColor = vbBlack
 End If

End Sub
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-18 13:30:01
| Show all posts
'Mousemove event that engages the form
Option Explicit
Dim b As Boolean

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    b = False
    Label1.BackColor = vbWhite
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If b = True Then Exit Sub
    Label1.BackColor = vbRed
    b = True
End Sub
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-18 20:30:02
| Show all posts
'Improve
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     If b = False Then Exit Sub
    Label1.BackColor = vbWhite
    b = False
End Sub
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-19 09:45:01
| Show all posts
Solved, thank you!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list