Basically what i want to do is....whenever i drag the form...i should be able to see the current top and left coordinates...i know there is a resize event but it does not updates top and left...it only updates height and width....

is there any way to simulate reposition event

Member Avatar for AlanC

Never having had to do this in VB, I was surprised at how hard it is!

The only way I can think of is to have a timer fire every second or so and compare the current form.left and form.top with the previous values. If they have changed, then handle this...

Option Explicit

Dim nOldTop As Long
Dim nOldLeft As Long

Private Sub Form_Load()
   'set timer up for 1 sec and start it
   Timer1.Interval = 1000
   Timer1.Enabled = True
   'remember the starting values
   nOldTop = Form1.Top
   nOldLeft = Form1.Left
   '
End Sub

Private Sub Timer1_Timer()
   If (Form1.Top <> nOldTop) Or (Form1.Left <> nOldLeft) Then
      'form has moved!!
      'remember the current values
      nOldTop = Form1.Top
      nOldLeft = Form1.Left
      'call the handler sub
      Call FormMoved(Form1.Top, Form1.Left)
   End If
End Sub

Private Sub FormMoved(ByVal ThisTop As Long, ByVal ThisLeft As Long)
     'form has moved:
     'do whatever you need to do...
     '
     MsgBox "The form's moved to " & Str(ThisLeft) & ", " & Str(ThisTop) & "!"
     '
End Sub

obviously you'll need to add a timer control.

Regards,
Alan

that was really a nice answer...it solved my purpose....but this is unneccessarily eating up my resources

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.