OVER OBJECTUSING THE MOUSE

  • Thread starter Thread starter SEAN DI''''ANNO
  • Start date Start date
S

SEAN DI''''ANNO

Hi,

I am trying to be clever with an object on my form. It is a picture of a
van and its position is determined by a field called status;

I have done this by using

Me.Brady_Van.Top = 2438.1

Code:
Select Case (Me.Status)
Case 1
Me.Brady_Van.Left = 340.2
Case 2
Me.Brady_Van.Left = 1927.8
Case 3
Me.Brady_Van.Left = 3214.89
Case Else
Me.Brady_Van.Left = 340.2
End Select

What I would like to do, is be able to hover over the object and when for
example the left mouse button is pressed move the van left or right. i.e. Add
1 to Status. Is this possible.
 
That may be a bit tricky. You could use the MouseMove event of the control,
but the problem will be that if you do something like
Me.Status = Me.Status + 1
It will start incrementing and keep doing so until you move the move away
from the control. You would have to come up with a way for it to increment
only once per occurance of moving the mouse.

It will start incrementing, but will kee
 
SEAN DI''''ANNO said:
Hi,

I am trying to be clever with an object on my form. It is a picture of a
van and its position is determined by a field called status;

I have done this by using

Me.Brady_Van.Top = 2438.1

Code:
Select Case (Me.Status)
Case 1
Me.Brady_Van.Left = 340.2
Case 2
Me.Brady_Van.Left = 1927.8
Case 3
Me.Brady_Van.Left = 3214.89
Case Else
Me.Brady_Van.Left = 340.2
End Select

What I would like to do, is be able to hover over the object and when for
example the left mouse button is pressed move the van left or right. i.e.
Add
1 to Status. Is this possible.

Put this code in the declarations section of your form's class module:

Private m_dragging As Boolean

Then create MouseDown, MouseMove and MouseUp event procedures for
Me.Brady_Van, like:

''' BEGIN CODE '''
Private Sub Brady_Van_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
m_dragging = True
End Sub

Private Sub Brady_Van_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If Button <> 0 Then
If m_dragging Then
On Error Resume Next
Brady_Van.Left = Brady_Van.Left + X
End If
End If
End Sub

Private Sub Brady_Van_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
m_dragging = False
End Sub
''' END CODE '''

Watch out for word wrap on the Private Sub lines. All up to and including
the 'As Single)' ought to be on one line.

That should get you started.
 
Back
Top