Results 1 to 3 of 3

Thread: VB6 - Remember App window Position and Size

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,476

    VB6 - Remember App window Position and Size

    Attached is a demo of saving and restoring an application position and size. Rather than hijacking Elroy's thread, I decided to create a new one. This code is further simplified from the code that I supplied there, in that it eliminates the need for the SysInfo control and doesn't account for the Taskbar. It also demonstrates how the onboard controls are adjusted when the form size is adjusted. This is a fairly simple demonstration, and more complex forms will take quite a bit more work. The "EXIT" button is there simply to allow the form to be unloaded when the right side is off the screen. The "InitFlg" in the "Resize" event simply prevents the controls from being adjusted on the intial activation.

    The InkEdit control used as "Text1" should allow for the use of Unicode characters.

    J.A. Coutts
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: VB6 - Remember App window Position and Size

    Thanks, but saving Form's position need to handle Maximized and Minimized states, e.g. if the form closed when it is minimized (select "Close window" from taskbar context menu), it will not start again due to Run-time error '380', if the form closed when it is maximized, it will start with normal state!



  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,476

    Re: VB6 - Remember App window Position and Size

    Ending a program from the Taskbar is not a good idea at any time, unless it is absolutely necessary. Having said that, ending the program while it is minimized stores the form Left, Top, and ScaleHeight as zero (but not the ScaleWidth?). You can avoid the error by changing:
    Code:
    If InitFlg And Me.ScaleWidth Then
    to:
    Code:
    If InitFlg And Me.ScaleHeight Then
    in the Form_Resize event. Alternately, you can trap the error and change the form WindowState to minimized, but it is not something I would recommend. I would also not recommend trying to restore the maximized setting, as even Windows programs like NotePad do not do that.

    J.A. Coutts
    Last edited by couttsj; Mar 26th, 2018 at 02:44 PM.

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