RollOver buttons in UserForms (A solution)

  • Thread starter Pierre Archambault
  • Start date
P

Pierre Archambault

Hi,

Last week I posted a message about creating a weblike "RollOver" on all
buttons in all the userforms contained in a VBA project. Nobody paid
attention except for Tom Ogilvy who suggested to look at John Walkenbach's
code for a technique to provide one
event for multiple controls.

At that time I already had some partially working code and I slept on my
little problem (just nice to have) for the rest of the week. Today I am
proud to say that I have found a way to do the job. It's short and sweet.

In the MouseMove event of each CommandButton of every UserForm, place this
piece of code:
---------------------------------------------------
Private Sub CmdOk_MouseMove(ByVal Button As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)

Dim MyButton As Control

Set MyButton = CmdOk '(Here you will have to use the name of the
current button)
Call RollOver(MyButton, X, Y)

End Sub
----------------------------------------------------

Then create this RollOver Sub in a Module
----------------------------------------------------
Public Sub RollOver(Button As Control, X As Single, Y As Single)

If X > 6 And X < Button.Width - 7 And Y > 4 And Y < Button.Height - 5 Then
Button.ForeColor = vbWhite
Button.BackColor = &HC00000 'Dark blue
Else
Button.ForeColor = vbBlack
Button.BackColor = &HC0C0C0 'My default colors
End If

End Sub
-----------------------------------------------------

The RollOver Sub tests for a peripheral zone all around and inside the
button. If the mouse enters that zone, the colors are set to the original
settings but if it continues further inside, the colors are changed to
whatever color you want. And when the mouse moves away from the button, it
passes over the surrounding "reset" zone again.

Neat isn't it. But there is a hitch... The mouse does'nt seem to trigger
the MouseMove event fast enough when it passes over the "reset" zone so that
it often fails to reset the colors. I tried to reduce the mouse pointer
acceleration and it's speed (in the control pannel) but that does'nt change
the results.

So if somebody has an idea, please let me know.

Pierre
 
L

Leyton

What about using the mousemove event of the userform
itself to reset the colours?

Leyton
 
P

Pierre Archambault

Yes it is a solution that I used before but then you have to code it in each
of the forms and if the buttons are positionned on top of an image or any
kind of other control, you'll have to put the code in that control too. And
if the buttons are standing side by side, touching each other, you need a
way to reset the colors when your mouse slides from one button to the other,
furthermore, if the adjacent button is disabled, moving over it wont trigger
it's MouseMove event.

Thanks for the hint.

Pierre
--------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top