I have button
I want to add shadow only when hover
How I do it?
I want to add shadow only when hover
How I do it?
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 :-(Option Compare Database
Option Explicit
Private Const conCB As String = "cmdTest"
Private Sub Form_MouseMove(Button As Integer, Shift As Integer _
, X As Single, Y As Single)
Dim lngFS As Long
With Me
With .Controls(conCB)
If X < .Left Or X > .Left + .Width _
Or Y < .Top Or Y > .Top + .Height Then
lngFS = 11
Else
lngFS = 15
End If
If .FontSize <> lngFS Then .FontSize = lngFS
End With
End With
End Sub
OnMouseMove event procedure..Shadow property - but which wasn't available in my version A2019 :-( CommandButton.S hadow 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.Option Compare Database
Option Explicit
Private Const conCB As String = "cmdTest"
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer _
, X As Single, Y As Single)
With Me.Controls(conCB)
If .Shadow <> 0 Then .Shadow = 0
End With
End Sub
Private Sub cmdTest_MouseMove(Button As Integer, Shift As Integer _
, X As Single, Y As Single)
With Me.Controls(conCB)
If .Shadow <> 1 Then .Shadow = 1
End With
End Sub
Shadow property - hence line #4 where it's set as a constant.
Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Command0.BorderColor = vbRed 'add a red border
Me.Command0.Properties("Shadow") = 1 'add a drop shadow at bottom right (or try 18 or 22)
End Sub
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Command0.BorderColor = RGB(132, 161, 198) 'restore blue border
Me.Command0.Properties("Shadow") = 0 'remove shadow
End Sub
.Shadow property earlier. Thanks for that again :-).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.
Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'check current state of control so it only changes once
If Not Me.Command0.BorderColor = vbRed Then Me.Command0.BorderColor = vbRed 'add a red border
If Not Me.Command0.Shadow = 1 Then Me.Command0.Shadow = 1 'add a drop shadow at bottom right (or try 18 / 22 etc)
End Sub
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'check current state of control so it only changes once
If Not Me.Command0.BorderColor = RGB(132, 161, 198) Then Me.Command0.BorderColor = RGB(132, 161, 198) 'restore blue border
If Not Me.Command0.Shadow = 0 Then Me.Command0.Shadow = 0 'remove shadow
End Sub
Comment