[VB6] Change Backstyle of Label when Mouse Over Label
Hello everyone! I am using Microsoft Visual Basic 6. My project has a Form with a Label. How do I change the BackStyle of the Label from Transparent to Opaque when the mouse is over the Label and back from Opaque to Transparent when the mouse is not over the Label? My code follows...
VB Code:
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackStyle = Transparent
End Sub
That code changes the BackStyle of the Label from Transparent to Opaque when the mouse is over the Label, but does not change it back from Opaque to Transparent when the mouse is not over the label. How do I do this? Thank you!
Re: [VB6] Change the BackStyle of the Label when Mouse is Over the Label
Add this:
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackStyle = 1
End Sub
Re: [VB6] Change the BackStyle of the Label when Mouse is Over the Label
Quote:
Originally Posted by Veritas2.0
Add this:
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackStyle = 1
End Sub
Is there another way of doing this, because if you move the mouse really fast from the label to another control, the BackStyle of the Label will not change back from Opaque to Transparent. Thank you!
Re: [VB6] Change Backstyle of Label when Mouse Over Label
One option would be to draw a transparent shape around the area that the label is at and extend it out further then the label is. Then when the mousemove event fires for the shape check to see if the user's mouse is inside the label. If it is then change it then change it to transparent, if its not then change it to opaque.
Ok nevermind about that I forgot that shapes don't have the mousemove event.
Re: [VB6] Change Backstyle of Label when Mouse Over Label
HA got it.
Try drawing a second invisible label that is bigger over the top of the first label. Then you just use the mousemove event on the second label to test to see if the mouse is inside or outside the first label
Code:
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X + Label2.Left > Label1.Left And X + Label2.Left < Label1.Left + Label1.Width) And (Y + Label2.Top > Label1.Top And Y + Label2.Top < Label1.Top + Label1.Height) Then
Label1.BackStyle = 0
Else
Label1.BackStyle = 1
End If
Debug.Print Label1.Left & "," & X & "," & Label1.Left + Label1.Width
End Sub
That should work if you place to labels on a form.