Results 1 to 5 of 5

Thread: [RESOLVED] How to tell if a form has been moved

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Resolved [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?
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width