Hgeocities.com/Heartland/Pond/4805/API11.htmgeocities.com/Heartland/Pond/4805/API11.htm.delayedxPJЮ8OKtext/htmlp0i8b.HSun, 20 Jan 2002 12:58:33 GMT3Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)en, *PJ8 Posted by Nicole Calinoiu---

Posted by Nicole Calinoiu---


Forms: Move and Resize form windows from code


    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    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 ************