Consulting

Results 1 to 3 of 3

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

  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 Guru
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    4,311
    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 - - - - -This is my signature, it appears after all my posts. Below is not directed at anyone in particular - so don't take offence! - (You might guess why it's there though)
    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 Wizard
    Joined
    Apr 2007
    Posts
    6,121
    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

    ------------------------------------------------------------------------------------------------------------------------
    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)
    (multiple files can be selected while holding Ctrl key) / 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
  •