0

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

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by SpS
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.