Results 1 to 5 of 5

Thread: [VB6] Change Backstyle of Label when Mouse Over Label

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Location
    White Oak, PA
    Posts
    25

    [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:
    1. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Label1.BackStyle = Transparent
    3. 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!
    Last edited by Shadowz O Death; Aug 20th, 2008 at 01:56 PM.

  2. #2
    Addicted Member Veritas2.0's Avatar
    Join Date
    May 2008
    Posts
    181

    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
    Simple little bugs 13 : Me 1

    Law of Bugs - That one bug you missed will be found almost immediately, by your customer.

    I wonder if anyone has ever asked for a User Surly interface?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Location
    White Oak, PA
    Posts
    25

    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!

  4. #4
    Addicted Member Veritas2.0's Avatar
    Join Date
    May 2008
    Posts
    181

    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.
    Simple little bugs 13 : Me 1

    Law of Bugs - That one bug you missed will be found almost immediately, by your customer.

    I wonder if anyone has ever asked for a User Surly interface?

  5. #5
    Addicted Member Veritas2.0's Avatar
    Join Date
    May 2008
    Posts
    181

    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.
    Simple little bugs 13 : Me 1

    Law of Bugs - That one bug you missed will be found almost immediately, by your customer.

    I wonder if anyone has ever asked for a User Surly interface?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width