Avatar of APD Toronto
APD TorontoFlag for Canada

asked on 

Mouse Hover

Hi Experts

Using VBA in PowerPoint, how can I achieve a Mouse Hover effect, so when the user moves the mouse over a button it changes color, then when it moves it out it changes another color?  Is this the MouseDown event, using the X & Y values?

Also, colors such as &H00FFFFFF& - are these hexadecimal? If no, can they be or RGB?

Thank you.
Microsoft PowerPointVisual Basic ClassicVBA

Avatar of undefined
Last Comment
APD Toronto
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of APD Toronto
APD Toronto
Flag of Canada image

ASKER

robr,

Expanding on your code, I'm trying the folowing, but nothing is happening

Sub hoverCalculate(oShp As Shape)

    oShp.Fill.BackColor.RGB = RGB(255, 0, 0)

        
End Sub

Open in new window

Avatar of APD Toronto
APD Toronto
Flag of Canada image

ASKER

Sorry, should've used ForeColor, which works.  However, what about reversing it back on MouseOut
Avatar of APD Toronto
APD Toronto
Flag of Canada image

ASKER

@James, there will be only 4 lines of code if I use MouseMove, and there are Top and Left properties of the object.  Isn't MouseMove viable?
Yes, you could always try it, but it will be more than 4 lines of code.

The thing is that you cannot know from which side the user will be entering. Same thing for the exit.

And you cannot simply check for the values of 0, button width and button height to determine if the cursor is on a border. I cannot say for Office, because I never had to use MouseMove with Office, but in other environments, MouseMove trigger on a timer instead of on the pixels. Many pixels can be skipped between 2 MouseMoves, so the first MouseMove for a cursor entering the control top might be at 1, 2 or 4, maybe more. You would have to test to see the amount of pixels you should consider around the control.

It will also be hard, to determine when the user is getting out, many situations will have to be considered.

Say that the user enter from the Left on a MouseMove at 4, then suddenly moves back out of the control. You will get only the Enter and will not be able to detect the exit. You need at least 2 MouseMove in order to detect both entry and exit.

Then, think of a user that moves horizontally very close to the top. You will get a series of Top positions that could oscillate between, let's say, 2 and 4 because the user is just a bit shaky. How will you know, in the sequence 2233432342, that the last 2 is the one getting you out of the control?

In my opinion, doing it with the MouseMove can work most of the time if properly done, but there will be many situations in which you won't be able to detect the mouse getting out.

For a user, nothing is annoying as erratic behavior.

One idea that I have while writing this. Playing with events often asks for creative ways to fix things.

Behind your Button, put a Label that is larger than the Button and make it the same color as the background, so that it does not show. When the user gets out of the Button, the Label will start receiving MouseMove. This is your indication that the cursor is out and that the Button should get back to normal.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo