Detecting/Correcting Off-Screen Form-VBForums
Results 1 to 3 of 3

Thread: Detecting/Correcting Off-Screen Form

  1. #1

    Thread Starter
    Join Date
    Mar 2014

    Detecting/Correcting Off-Screen Form

    Good Day,

    I'm hoping to address an intermittent issue with forms that display off-screen. We'd like an elegant way to determine this, and if so, correct the issue by bringing the form on-screen.

    We have a particular form that saves the position of the form on close to provide a consistent experience for users. However, if the user happens to move this form to their secondary monitor and then attempt to use the application when not connected to their dock this issue occurs. Walking users through how to correct is an option but not a long-term solution. Hoping the experts here can point me in the right direction.

    Any assistance is greatly appreciated!

    Best Regards

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Near Nashville TN

    Re: Detecting/Correcting Off-Screen Form

    Hi Brad,

    I believe I gave you the answer to centering on multiple monitors in your other thread. However, I've also had the problem you outline in this procedure. I didn't solve the problem with an implicit-automated solution. Rather, I just checked the form (and the saved Top and Left) each time it loaded.

    I tend to save this kind of information in the registry, as my application is multi-user, but each user might like their own settings regarding form-placement. Here's some code in a Form_Load of a form that saves its last position (to solve the problem you mention):

        Top = GetSetting(App.Title, "Settings", "TekscanControllerTop", (ScreenHeight - Height) \ 3)
        Left = GetSetting(App.Title, "Settings", "TekscanControllerLeft", (ScreenWidth - Width) \ 2)
        If Top + Height > ScreenHeight Then Top = ScreenHeight - Height
        If Left + Width > ScreenWidth Then Left = ScreenWidth - Width
        If Top < 0 Then Top = 0
        If Left < 0 Then Left = 0
    And in Form_Unload, I have the following:

        SaveSetting App.Title, "Settings", "TekscanControllerTop", Top
        SaveSetting App.Title, "Settings", "TekscanControllerLeft", Left
    I suppose I could write a general purpose procedure to check that stuff, but I don't do it all that often.

    Good Luck,

    EDIT1: Also, those ScreenHeight and ScreenWidth calls are functions I wrote. You can find the code for them in the CodeBank reference I gave you in the other thread. I don't use Screen.Height or Screen.Width because they're buggy. If you put your monitor in portrait mode (and even tell Windows), VB6 doesn't necessarily get that information, and confuses Height with Width.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    Join Date
    Feb 2006

    Re: Detecting/Correcting Off-Screen Form

    This why GetWindowPlacement/SetWindowPlacement exist. They deal with this issue:

    If the information specified in WINDOWPLACEMENT would result in a window that is completely off the screen, the system will automatically adjust the coordinates so that the window is visible, taking into account changes in screen resolution and multiple monitor configuration.

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