Rollover images

  • Thread starter Thread starter Mario
  • Start date Start date
M

Mario

Can anyone give ma an example of Rollover objects in access

for example:
There's a picture on a form and when you roll mouse over a button the
picture changes into another. when you rollout a button the picture changes
into a default state.
 
Hi,

Create a form, and add two image controls, Image6 and Image 7 (of course you
can use any name you want and as many controls you need)
To each image control, set the picture prop to the original image you want,
and enter the path to the second image (you want to have when the mouse is
over the img control) in TAG property (it is not used, so you can use it for
this purpose)

In the form module add the following code:

' last image control name you was with the mouse over
Dim cLastVisited As String

Private Sub Form_Open(Cancel As Integer)
cLastVisited = ""
End Sub

Add the following code into form's MouseMove event. This will restore the
original image for last rollover image control.

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If cLastVisited <> "" Then
On Error Resume Next
Dim c As String
c = Me.Controls(cLastVisited).Picture
Me.Controls(cLastVisited).Picture = Me.Controls(cLastVisited).Tag
Me.Controls(cLastVisited).Tag = c
cLastVisited = ""
End If
End Sub

Add the following code to Image 6 and Image 7 MouseMove controls

Private Sub Image6_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If cLastVisited = "" Then
cLastVisited = "Image6"

Dim c As String
c = Me.Image6.Picture
Me.Image6.Picture = Me.Image6.Tag
Me.Image6.Tag = c
End If
End Sub

Private Sub Image7_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If cLastVisited = "" Then
cLastVisited = "Image7"

Dim c As String
c = Me.Image7.Picture
Me.Image7.Picture = Me.Image7.Tag
Me.Image7.Tag = c
End If
End Sub

This approach has few drawbacks. If you overlapped the Image6 and Image7,
and if you move the mouse from one to another without moving over some empty
space on the form, the first control will fail to restore to original image
Also, if the controls are too close, and you move FAST from one image to
other, it might be possible form's MouseMove event do not raise, so again,
the first control will fail to restore.

If you have more questions, or need more help, you can contact me back.

HTH,
Bogdan Zamfir
__________________________

Independent consultant
 
Back
Top