[RESOLVED] How to tell if a form has been moved
I want to set up a program that saves the location of each form as soon as any form has been moved and also stops a user from moving any form into a certain part of the screen. If it helps (or hinders), it is in an MDI form and the MDI seems to work properly how I want it now, I just want to be able to at least save locations of the forms and be able to control where they're moveable to.
Is there any easy way to do this?
Re: How to tell if a form has been moved
The 'easy' way is to use a Timer and repeatedly check:
http://www.vbforums.com/showthread.php?t=411969
..but that is inefficient, as it does work all of the time when usually nothing will happen.
The 'proper' way is to subclass the WM_Move and WM_Moving messages:
http://www.vbforums.com/showthread.php?t=243465
Re: How to tell if a form has been moved
Saving the form position is easy enough. Just save it in the Form's QueryUnload or Unload events; you shouldn't have to save position every time it moves a pixel or so? As for restricting a form's position, subclassing is probably the answer.
Edited: si_the_geek & I posted same time; my recommendation is similar
Re: How to tell if a form has been moved
Thanks to both of you...I looked through the subclassing code and I'll reread it until hopefully I understand it better and may use it in future, but LaVol's suggestion of saving it on queryunload is actually probably a simpler way for the form locations (although of course I'll have to use subclassing if I want to limit where the form can be moved to, I'll do that later)
Timer sounds like one of my amateur ways of doing the saving, but I don't think it'd be efficient enough as there are a number of forms that'd need checking...as you say, it's inefficient and at the worst I would probably have set something up on form unload eventually when I finally realised that it would have been the best way to do it. This just saves a lot of time :-)
Re: [RESOLVED] How to tell if a form has been moved
The saving (and any other 'form is closing' type code) should actually be in the _Unload event, because _QueryUnload can happen without the form unloading - particularly when MDI forms are involved.
In terms of limiting the location, subclassing is really the only sensible way to implement it during the movement... but there may be an even better (and much simpler) way to do the equivalent - depending on what kind of locations you are limiting from and why.