473,433 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,433 software developers and data experts.

Button hover shadow

5 2Bits
I have button
I want to add shadow only when hover
How I do it?
Mar 12 '23 #1

✓ answered by isladogs

Sorry to disagree but the Shadow property has in fact been available since Access 2010 when Quick Styles were introduced.
However, like the rest of the Quick Styles items, it isn't shown in the button's control sheet

The syntax is either CommandButtonName.Properties("Shadow") or just CommandButtonName.Shadow

So for example, if you have a button called Command0, you can use code like this on the button's mouse move event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     Me.Command0.BorderColor = vbRed 'add a red border
  3.     Me.Command0.Properties("Shadow") = 1 'add a drop shadow at bottom right (or try 18 or 22)
  4. End Sub
  5.  
You will then need to remove that code when you move away from the button so use code like this in the form's Detail_MouseMove event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     Me.Command0.BorderColor = RGB(132, 161, 198) 'restore blue border
  3.     Me.Command0.Properties("Shadow") = 0 'remove shadow
  4. End Sub
  5.  
I have attached a simple example demonstrating the use of the above code.

Also, see the Microsoft Help article: CommandButton.Shadow property

5 6713
NeoPa
32,556 Expert Mod 16PB
In simple terms you would have the shadow turned off by design and then turn it on & off within the Event procedure for the form's Move event, depending on the latest position of the pointer as reported.

Unfortunately, when I looked in my 2019 version, I found no way to turn shadowing on or off :-(

I also had difficulties making sense of the Form_MouseMove documentation on Microsoft's web site. I left a comment to that effect but couldn't get it to work even to change the size of the font :-(

However, I will keep this flagged and attempt to find out more for you. Watch this space.

In the meantime, the basic logic should be something like the following which I knocked up to test :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Const conCB As String = "cmdTest"
  5.  
  6. Private Sub Form_MouseMove(Button As Integer, Shift As Integer _
  7.                          , X As Single, Y As Single)
  8.     Dim lngFS As Long
  9.  
  10.     With Me
  11.         With .Controls(conCB)
  12.             If X < .Left Or X > .Left + .Width _
  13.             Or Y < .Top Or Y > .Top + .Height Then
  14.                 lngFS = 11
  15.             Else
  16.                 lngFS = 15
  17.             End If
  18.             If .FontSize <> lngFS Then .FontSize = lngFS
  19.         End With
  20.     End With
  21. End Sub
You can ask questions about this once you've read & tried to understand it.

Here's the basic design of the form. Very simple with a Button control in the middle of an otherwise empty form with a 1cm gap on all sides.

Attached Images
File Type: jpg Bytes.Jpg (34.5 KB, 549 views)
Mar 12 '23 #2
NeoPa
32,556 Expert Mod 16PB
I now learn, from a few of the other Access MVPs who generously chipped in to help me understand this better, that each object (Section, Command Button, etc.) needs to be handled by its own OnMouseMove event procedure.

I also learned that there is a .Shadow property - but which wasn't available in my version A2019 :-( CommandButton.Shadow property (Access) explains how it needs to be set for the various different possible options. In my code below I'll use the value 1 to set it and 0 to clear it.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Const conCB As String = "cmdTest"
  5.  
  6. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer _
  7.                            , X As Single, Y As Single)
  8.     With Me.Controls(conCB)
  9.         If .Shadow <> 0 Then .Shadow = 0
  10.     End With
  11. End Sub
  12.  
  13. Private Sub cmdTest_MouseMove(Button As Integer, Shift As Integer _
  14.                             , X As Single, Y As Single)
  15.     With Me.Controls(conCB)
  16.         If .Shadow <> 1 Then .Shadow = 1
  17.     End With
  18. End Sub
Note that, even though one of the event procedures is set specifically for the Command Button object itself, the code still needs to use the name of the object in order to reference it when setting it's Shadow property - hence line #4 where it's set as a constant.
Mar 12 '23 #3
isladogs
456 Expert Mod 256MB
Sorry to disagree but the Shadow property has in fact been available since Access 2010 when Quick Styles were introduced.
However, like the rest of the Quick Styles items, it isn't shown in the button's control sheet

The syntax is either CommandButtonName.Properties("Shadow") or just CommandButtonName.Shadow

So for example, if you have a button called Command0, you can use code like this on the button's mouse move event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     Me.Command0.BorderColor = vbRed 'add a red border
  3.     Me.Command0.Properties("Shadow") = 1 'add a drop shadow at bottom right (or try 18 or 22)
  4. End Sub
  5.  
You will then need to remove that code when you move away from the button so use code like this in the form's Detail_MouseMove event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     Me.Command0.BorderColor = RGB(132, 161, 198) 'restore blue border
  3.     Me.Command0.Properties("Shadow") = 0 'remove shadow
  4. End Sub
  5.  
I have attached a simple example demonstrating the use of the above code.

Also, see the Microsoft Help article: CommandButton.Shadow property
Attached Files
File Type: zip ButtonHover.zip (19.7 KB, 75 views)
Mar 12 '23 #4
NeoPa
32,556 Expert Mod 16PB
Hi isladogs.

Before I continue I should add that he was indeed one of the other Access MVPs who steered me in the right direction on the .Shadow property earlier. Thanks for that again :-)

I'm happy for you to disagree on when it was introduced. I'd rather be shown up than steer anyone incorrectly. I'd made an assumption as to the cause of my not seeing it but that appears incorrect. I tried to check but the documentation had nothing on it I could find.

As for the use of the .Shadow property, I have since updated the code to show what I'd meant before. The text explains the situation correctly but I'd forgotten to change the code from my own testing and I'd used different font sizes to test the concept worked before posting. As you can see I used the simpler second alternative that you show rather than using the .Properties() collection.
Mar 13 '23 #5
isladogs
456 Expert Mod 256MB
Hi NeoPa
That's better! Your corrected code does indeed work.

For the benefit of the OP, using the simplest version of the code as in my post #4 will cause screen flicker as the code will repeatedly update the appearance every time the mouse moves. To prevent that, add code (as @NeoPa did in post #3) to first check the current state of the button so the changes only occur once. My variation on that idea is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3.     'check current state of control so it only changes once
  4.     If Not Me.Command0.BorderColor = vbRed Then Me.Command0.BorderColor = vbRed 'add a red border
  5.  
  6.     If Not Me.Command0.Shadow = 1 Then Me.Command0.Shadow = 1 'add a drop shadow at bottom right (or try 18 / 22 etc)
  7. End Sub
  8.  
  9. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  10.  
  11.    'check current state of control so it only changes once
  12.     If Not Me.Command0.BorderColor = RGB(132, 161, 198) Then Me.Command0.BorderColor = RGB(132, 161, 198) 'restore blue border
  13.  
  14.     If Not Me.Command0.Shadow = 0 Then Me.Command0.Shadow = 0 'remove shadow
  15. End Sub
Mar 13 '23 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: bart plessers | last post by:
Hello, Somewhere in my code I have <input TYPE="button" NAME="btnFirst" VALUE="<<" OnClick="GetFile('1')" DISABLED> I changed the layout of the INPUT with a stylesheet to INPUT { color:...
0
by: bart plessers | last post by:
Hello, Somewhere in my code I have <input TYPE="button" NAME="btnFirst" VALUE="<<" OnClick="GetFile('1')" DISABLED> I changed the layout of the INPUT with a stylesheet to INPUT { color:...
5
by: JohnSouth | last post by:
Hi I've an image submit button on a form that needs to appear flat on the surface. I can't get rid of the shadow that appears bottom and right. This is the best I can do. <code>...
3
by: jack | last post by:
Hi.. aaa... i tried a lot btu couldnt find on net, Im trying to get the hover effect of the web button . but dont know how to get this .. Please help Thanks Awaiting for the answer..
0
by: phil-news-nospam | last post by:
The following test/experiment page has a drop shadow in CSS that also uses the hover selection to modify the apparent height perception the drop shadow is doing. The problem is the top-right and...
4
by: phil-news-nospam | last post by:
I bet this won't work in IE> http://phil.ipal.org/usenet/ciwas/2006-05-04/more-shadow-boxes.html Move the mouse pointer from box to box. Comments (on other than it's silliness and absurdity)...
4
by: tomb | last post by:
In FF 2 and Netscape 7.2 this button works exactly as desired, and that is hovering anywhere over the button activates the hover action. But in IE 6, only mousing over the text of the link...
1
by: msk1 | last post by:
The code works fine in JSFIDDLE, both in Mozilla and IE, but when I paste this code in my facebook iFrames tab, I get crazy scroll down in IE/Chrome (Mozilla works fine just like in JSFIDDLE). ...
0
nomad
by: nomad | last post by:
Hello Everyone: I need some help on resolving a problem. Inside my sytle_buttons.css file there is an code that is blocking input fields in the contact form. is there away to avoid using the...
0
by: ahmedsalem | last post by:
Is it possible to implement mouse hover selection by hover on the object and drawing a circle and drag selection hover box in WPF. what I want specifically when the user hover on the button a by...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.