Location, Location, Location, VB 6 Version - September 1998

This tip-of-the-month gathers into one module, functions and subroutines that set a window's location, build a form's Window menu, allow users to size a window using standard resolution settings [800x600, etc.] and arrange MDI child forms. If any, the initial window location information is retrieved from the registry. Location information is stored in the registry when the form is unloaded. Click here to view the VB.Net version of this tip.

Form Positioning Routines

Sub or Function Description
TB_CenterForm Center the form on the screen. Does not consider the task bar.
TB_CenterForm32 Center the form in the desktop work area, exclude the task bar.
TB_FillDesktop32 Resize the form to use all the desktop work area.
TB_CenterFormInMDI Center a child form within its MDI form.
TB_FillFormInMDI Resize the child form to use all the MDI work area.
TB_Zone Set a screen zone to be used by the centering routines. Sets the screen quadrant. Use this before loading a non-child form. Then use TB_CenterForm to center the form in the quadrant.
TB_ZoneFullScreen After using TB_Zone use this to reset the screen quadrant.
TB_MakeSureOnScreen Make sure the form is fully displayed on the screen. Use this routine during the form load event.
TB_GetFormInformation Get information about the form's location from the registry. Use this routine in the form load event.
TB_SaveFormInformation Save form information into the registry. Call this routine in the form unload event.
TB_GetScreenSize Get the current screen size. Works in conjunction with the following routine.
TB_SaveScreenSize Save the current screen size. Call during the application unload process. Use TB_GetScreenSize and the current screen sizes to determine if the user has changed screen resolution since the application was last run. If so then use function 'TB_MakeSureOnScreen' to make sure forms fit on the screen.
TB_GetDesktopWorkArea Used to get the left, top, width and height of the desktop area. Used by the above centering in desktop area routines. It can be used directly.
TB_DoDock Will dock a window in the Left, Right, Top or Bottom positions of the desktop area. Added 2001/01/28.
TB_DoCorner Will move a window to the upper left, upper right, lower left or lower right corner of the desktop area. Added 2002/08/12.

Window Menu Items

The following Window menu items are typically created:

Typical Window Menu

TB_BuildWindowMenu Dynamically build the menu. You can specify whether of not the 'Arrange' items are displayed.
The highest resolution supported on the user's computer [exclusive of the task bar] is displayed. In this example it is 1152x864. Typically this will be one resolution lower than the actual display setting - the task bar uses some screen space. Optional parameters:
vntNoBuildArrangeMenu True/False If True then no arrange menu is created.
vntDockMenu True/False If True then build the 'fill' menu.
vntNoBuildSizeMenu True/False If True then no size menu is created.
vntCornerMenu True/False If True then build the 'corner' menu.
TB_Window frm Menu pre-processor which enables or disables menu items based upon the current window state. For example: the 800x600 menu item is disabled if the form is currently displayed at that resolution. Call from the mnuWindow_Click event.
TB_WindowItem frm, Index Process the window menu item. For example, if the user selects 'Center' then the form is centered.  Call from the mnuWindowItem_Click event.
TB_SetWindowMenuUseMinMax Can be used to pass minimum and maximum window sizes which disable menu sizing entries. Can be used in conjunction with clsMinWindow.

The Demo Application

I wrote an MDI application to demonstrates the routines.  The MDI form:

MDI Form (mdi.jpg (34645 bytes))

Contained in the top picture box are four commands used with the MDI form. They are self explanatory. The commands shown in the bottom picture box are used to load additional child or non-child forms. Sample child forms are shown above in the MDI form. A sample, non-child form:

Non Child Form (nonchild.jpg (21380 bytes))

Using Offsets

Most of the centering routines accept optional offset values. The value is added to the move operation. For example: Set the left offset to 500 and the top offset to -500 before calling a center command. The form will be moved right 500 and up 500 twips.

Using the Routines

You will need to add the following modules to your application if you want to use these routines:

modLocationLocationLocation.bas The routines described in this document.
modReg.bas Routines used to read and write to the registry. Click here to review RegRead documentation.


Date Description
Jan 28, 2001 Screen resolution settings are updated to support Large Fonts. The formula used to calculate screen sizes did not consider a possible Windows Large Font setting. It does now. The updated code was saved using VB6. VB4 is no longer supported.
May 10, 2001 The June 2001 tip of the month shows how to set minimum and maximum screen sizes. Function TB_SetWindowMenuUseMinMax was added to support this new capability. See clsMinWindow for details.
October 8, 2001 Added support for large resolutions [1400 x 1050 and 1600 x 1200].
Aug 12, 2002 Added the corner menu support [Top Left, Bottom Right, etc.] and fixed a few bugs.
Jan 17, 2003 Added support for 1280 x 768. This size is used by the Sony SDM-V72W [wide] monitor. A monitor I began using recently.
Oct 19, 2005 Add tool tips to commands and command Enums. Replaced support modules with latest versions.

Download VB Code

Click here to download the VB 6 Source Code [24k]. 

Click here to download the VB.Net Source Code [68k].

Previous Tip    Tip Index    Next Tip


Updated 2006/11/26