Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Positioning forms in code?

1,304 views
Skip to first unread message

Andy Kestle

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
Hi all,
I want to be able to position a pop-up form just below a specific record in
multi-form view, so that when the mouse is clicked for an individual record
some info appears just below, (like the tooltips popup).
(e.g. I click on 4th record and form appears just below it, or click the12th
record and the pop-up form appears just below that one etc).
A form does not have a Left or Top property, so does anyone know how I can
specify where the form will be positioned on the screen?

TIA
Andy

Danny J. Lesandrini

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
The closest I could come to that was to use the GetCursorPos
API Function. Put this Declare and Type in a public module.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Declare Sub GetCursorPos Lib "user32" (lpPoint As typPOINTAPI)

Type typPOINTAPI
x As Long
y As Long
End Type

Public lngCalendarLeft As Long
Public lngCalendarTop As Long
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Call the function to get the coordinates of the cursor and
store those values in global variables.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ShowCalendar()
On Error Resume Next

Dim TipPoint As typPOINTAPI

GetCursorPos TipPoint

' Get X and Y positions and put them
' in global variables for the Calendar Form
lngCalendarLeft = TipPoint.x
lngCalendarTop = TipPoint.y

DoCmd.OpenForm "frmCalendar"

End Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When the form opens, use DoCmd.MoveSize with the
public variables to reset it's position:

Private Sub Form_Load()
DoCmd.MoveSize lngCalendarLeft, lngCalendarTop
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--

Danny J. Lesandrini
dan_n...@yahoo.com

"Andy Kestle" <kake...@glam.ac.uk> wrote in message news:8dhhuk$bv6$1...@mannews.swan.ac.uk...

Lyle Fairfield

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
' click opens form .. dialog mode is required

Private Sub txtDescription_Click()
DoCmd.OpenForm "frmFoods", , , , , acDialog
End Sub

' form's on open code
Private Sub Form_Open(Cancel As Integer)
' 3rd argument (optional) is control in new from where focus should begin
FormPlacement Application.Screen.ActiveControl, Me, Me.txtCategory
End Sub

' in standard module
Option Compare Database
Option Explicit

Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Type Dimensions
Width As Long
Height As Long
End Type

Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long)
As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect
As Rect) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal
hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long,
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOP = 0
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOZORDER = &H4

Public Function FormPlacement(ByRef ctl As Control, ByRef frm As Form, Optional
ByRef ctlSetFocus As Control)
Dim CtlRect As Rect
Dim frmRect As Rect
Dim frmDimensions As Dimensions
Dim scrDimensions As Dimensions
Dim wFlag As Long
CtlRect = ControlRect(ctl)
frmDimensions = FormDimensions(frm)
With scrDimensions
.Width = GetSystemMetrics(SM_CXSCREEN)
.Height = GetSystemMetrics(SM_CYSCREEN)
If (.Width - CtlRect.Right) > CtlRect.Left Then
frmRect.Left = CtlRect.Right
Else
frmRect.Left = CtlRect.Left - frmDimensions.Width
End If
If (.Height - CtlRect.Bottom) > CtlRect.Top Then
frmRect.Top = CtlRect.Top
Else
frmRect.Top = CtlRect.Bottom - frmDimensions.Height
End If
End With
If ctlSetFocus Is Nothing Then
wFlag = SWP_NOZORDER
Else
wFlag = SWP_SHOWWINDOW
End If
SetWindowPos frm.hWnd, HWND_TOP, frmRect.Left, frmRect.Top, _
frmDimensions.Width, frmDimensions.Height, wFlag
frm.Visible = True
If Not ctlSetFocus Is Nothing Then ctlSetFocus.SetFocus
End Function

Private Function ControlRect(ByRef ctl As Control) As Rect
ctl.SetFocus
GetWindowRect GetFocus(), ControlRect
End Function

Private Function FormDimensions(ByRef frm As Form) As Dimensions
Dim frmRect As Rect
GetWindowRect frm.hWnd, frmRect
With FormDimensions
.Width = frmRect.Right - frmRect.Left
.Height = frmRect.Bottom - frmRect.Top
End With
End Function

kake...@glam.ac.uk (Andy Kestle) wrote in
<8dhhuk$bv6$1...@mannews.swan.ac.uk>:

>Hi all,
>I want to be able to position a pop-up form just below a
>specific record in multi-form view, so that when the mouse is
>clicked for an individual record some info appears just
>below, (like the tooltips popup). (e.g. I click on 4th record
>and form appears just below it, or click the12th record and
>the pop-up form appears just below that one etc).
> A form does not have a Left or Top property, so does anyone
> know how I can
>specify where the form will be positioned on the screen?
>
>TIA
>Andy


--
Lyle
http://www.cyriv.com/

0 new messages