Link to home
Start Free TrialLog in
Avatar of Maximka
Maximka

asked on

Form Move Event

How can I catch Form Move Event ?

Any ideas ?...
Thanks.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

You can verify the coordinates at fixed interval (with a timer control for example):

Private Sub Form_Load()
    With Timer1
        .Interval = 500
        .Enabled = True
    End With
End Sub

Private Sub Timer1_Timer()
Static lngLeft As Long
Static lngTop As Long

    If lngLeft <> Me.Left Or lngTop <> Me.Top Then
        lngLeft = Me.Left
        lngTop = Me.Top
        Beep
    End If
End Sub
The previous solution works, but it has the unconvient that you will always have the 500 ms delay.
You may instead
* change to C++, Delphi or other language developing (-;
* try to implement a frame that you use instead of a standard form caption (the move corresponds to a "OLEDrag" of the frame). OK, this is not nice as solution
* I think there must be a control of some third-party vendor that gives you this (i saw it once, but i don't know any longer). I may try to find it again.

ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paulstamp
paulstamp

Hmmm... I agree with vbmaster that change to C++ or Delphi is a cop-out, however subclassing should be undertaken with EXTREME CAUTION.

I dont mean to be patronising as I am very wary of it meyseld, but subclassing is  a powerful technique it is VERY DANGEROUS and I would only advocate it for situations where your code is pretty much finished, or if you don't mind seeing lots of blue-screens as you try to debug.

I repeat : subclassing gives you lots of control over windows operations, but unless you are very sure you know how the fundamentals of Windows works STEER CLEAR.

I admit that using timer controls is a bit of a hack I but I would advocate using emoreau's approach unless you are 100% confident with subclassing or are fairly sure that your code is complete and wont need debugging <smile>.
For VBmaster:
I know what it means to implement in VB something that is not in the helpfile (.;
BUT even if you seem to prefer VB over C++, if I see it closely, what you do is call Windows API in you Subclass(which is nothing else than C).

For Maximka:
This solution is clearly a good Windows solution!
Avatar of Maximka

ASKER

Thanx man, it just Excellent!!!
As for the crashes in VB.. I use the DLL file from vbaccelerator as long as I debug, and when it's time to distribute the product it's a easy task to replace the DLL with the pure-VB code.

angelIII: and if you look really close you see that when you create a window in a VB program you are actually calling the OS and telling it to create a window, so no more windows then? ;)