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):
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
2. To move a form to the top right corner of the Access window:
Public Sub MoveToTopRight(ByVal strFormName As String)
Dim fwForm As New clFormWindow
Const SMALL_OFFSET = 5
With fwForm
.hwnd = Forms(strFormName).hwnd
.Top = .Parent.Top
.Left = .Parent.Width - .Width - SMALL_OFFSET
End With
Set fwForm = Nothing
End Sub
|