Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Move and Resize form windows from code

Author(s)
Nicole Calinoiu

   Often times, it's necessary to open forms in specified locations and size them to a custom size. Windows API are the most convenient way of doing this, but the converting between the different coordinate systems can be a pain.

      Download clFormWindows.Bas

    This Class Module hides the API functions and provides generic methods to move and size your forms. The class, once imported in your application, can be used in in a couple of ways.

    1. To align the tops of two forms (at the position of the topmost form):

'********** Code Start ************
Public Sub AlignTops(ByRef frmA As Form, ByRef frmB As Form)
  Dim fwA As New clFormWindow, fwB As New clFormWindow
  fwA.hwnd = frmA.hwnd
  fwB.hwnd = frmB.hwnd
  If fwA.Top < fwB.Top Then
    fwB.Top = fwA.Top
  Else
    fwA.Top = fwB.Top
  End If
  
  Set fwA = Nothing
  Set fwB = Nothing
End Sub
'********** Code End  ************

    2. To move a form to the top right corner of the Access window:

'********** Code Start ************
Public Sub MoveToTopRight(ByVal strFormName As String)
  Dim fwForm As New clFormWindow
  Const SMALL_OFFSET = 5  'Used to position window slightly _
  			  away from the Access MDI window border _
                          in order to avoid appearance of the Access _
                          window vertical scroll bar.
  With fwForm
    .hwnd = Forms(strFormName).hwnd
    .Top = .Parent.Top
    .Left = .Parent.Width - .Width - SMALL_OFFSET
  End With
  Set fwForm = Nothing
End Sub
'********** Code End ************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer