is it possible at all to detect the mouse over event of a toolbar. say if the mouse is over a certain button, i want to do something. thanks!
Who is Participating?
VbmasterConnect With a Mentor Commented:
Put this in the MouseMove event..

  Dim BButton As Button
  For Each BButton In Toolbar1.Buttons
    If (BButton.Left <= x) And (BButton.Left + BButton.Width >= x) Then
      If (BButton.Top <= y) And (BButton.Top + BButton.Height >= y) Then
        Me.Caption = BButton.Index
        Exit For
      End If
    End If

The caption of the window is changed according to what button the mouse is over.
foxhoundAuthor Commented:
the code works great but how do i make the event to control the mouse is not on top of the toolbar anymore? thanks
What you could do is to add a private variable (i.e. m_ButtonOver), and set that value to the BButton.Index in that For Each..Next loop. Then add this code in the beginning of the MouseOver event, just before the For Each.. Next loop

  If (m_ButtonOver > 0) Then
    Set BButton = Toolbar1.Buttons(m_ButtonOver - 1)
    If (BButton.Left <= x) And (BButton.Left + BButton.Width >= x) And (BButton.Top <= y) And (BButton.Top + BButton.Height >= y) Then
      'Still over the same button, so quit this function now damn't!
      Set BButton = Nothing
      Exit Sub
    End If
    Set BButton = Nothing
  End If

And you will have to add the line

  m_ButtonOver = BButton.Index + 1

right after that "Me.Caption = BButton.Index" line you had, or whatever you have exchanged it to.
foxhoundAuthor Commented:
sorry to ask again, but i didn't quite get what the code does in the above. what i want is to change me.caption back to nothing if the mouse is not over the toolbar. the last code may work but o dunno how to use it with the previous code. thanks once again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.