Consulting

Results 1 to 5 of 5

Thread: Change Color Of Labels As Mouse Moves (Using MouseOver event)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    1
    Location

    Change Color Of Labels As Mouse Moves (Using MouseOver event)

    I have created an user form which has a frame. The frame contains several labels. My objective is to highlight the label when mouse points to that label but highlight should disappear once mouse moves to next label and the next label should be highlighted.

    Following is my code:

    
    
    Code is my user form:
    
    
    Dim Labels() As New LblClass
    
    
        Dim LabelCount          As Long
        Dim ctl                 As Control
    
    
    
    
        ' Create the Label objects
        LabelCount = 0
        For Each ctl In Frame1.Controls
           If TypeName(ctl) = "Label" Then
              LabelCount = LabelCount + 1
              ReDim Preserve Labels(1 To LabelCount)
              Set Labels(LabelCount).LabelGroup = ctl
           End If
        Next ctl
    
    
    
    Created a class called LblClass and this class has following code:
    
    
    Public WithEvents LabelGroup As MSForms.Label
    
    
    
    
    Private Sub LabelGroup_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    
    
    
       LabelGroup.ForeColor = vbWhite
       LabelGroup.SpecialEffect = 1
       LabelGroup.BackStyle = 1
       LabelGroup.BackColor = &H808000
       
    End Sub



    With above code, when mouse moves over a label it is highlighted. Next when mouse moves over a new label, new label is highlighted and old label is still highlighted. This continues. How can I remove the highlight from my previous label when mouse moves over new label.

    Thanks
    Angsuman



  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    Could you supply a file with this as you currently have it - save us having to setup our own files and guess (wrongly) what's in yours?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    I had done something like that awhile ago, except I got carried away and did a number of different types of controls

    I needed to polish an application to make it stand out -- the highlighting is pretty much just eye candy since it really is only part of the UI

    I used the

    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    event to 'clear' the highlight color

    The attached file has the idea. It's a little crude, but now that I've looked at it, I might play around some more
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Paul, very impresive.
    If I could make one suggestion, adding this to the EnhancedCheckbox (and option button), so the background color reacts when a control is checked.
    Private Sub CheckBoxEnhanced_Change()
        Call CheckBoxEnhanced_MouseMove(Button:=1, Shift:=0, X:=0, Y:=0)
    End Sub

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Thanks and Thanks. Very nice addition

    As I said, I started to play with it a little more, just for the heck of it (retired now so these are just fun little projects for me)

    I tried to define a new base class clsEnhancedControl to build the 'real' enhanced controls off of, but the Control object doesn't expose the MouseMove and Change events that I wanted, so now I'm re-thinking the approach
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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