View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pierre Archambault Pierre Archambault is offline
external usenet poster
 
Posts: 35
Default RollOver buttons in UserForms (A solution)

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