Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Forms

Status
Not open for further replies.

ShaneBrennan

Programmer
May 19, 1999
198
GB
Hi Everyone. In have a form that I want to move around the screen, but I want to limit where I can move it on the screen. Specifically I don't want it to go into the 1st 1" of the screen. The form is a pop-up.

The reason I don't want it to go to the top of the screen, if because I have another pop-up form at the top of the screen that I am using as a toolbar.

I am using access 97.

thank you for any help you can offer.

Shane Brennan

'-----------------------

' Emails: shanebrennan@postmaster.co.uk


 
Have a look at the DoCmd.MoveSize method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hi pvs

I have used it to position the toolbar - but I am unsure how to retrieve the position of the form.

Shane Brennan

'-----------------------

' Emails: shanebrennan@postmaster.co.uk


 
Hi PHV

I've sorted it - well for now I'm happy with the code but I'm sure I can do better later.

I used SetWindowPos, GetWindowRect and a timer (set to 1000) on each form I wanted to ensure was always positioned 60 pixels below the top of the screen (just below my toolbar). ALL forms that wish to use this technique must be POP-UPS!

Ok here goes

Module Code
-----------

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Sub 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)

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long


Public Sub RepositionBelowToolBar(hwnd As Long)
Dim ThePositions As RECT
If GetWindowRect(hwnd, ThePositions) = 0 Then
MsgBox "error occured with retrieving window location"
Else
SetWindowPos hwnd, HWND_NOTOPMOST, ThePositions.Left, 60, ThePositions.Right - ThePositions.Left, ThePositions.Bottom - ThePositions.Top, SWP_SHOWWINDOW
End If
End Sub



Form Code
----------

Private Sub Form_Timer()
Dim ThePositions As RECT
ThePositions = GetWindowPosition(Me.hwnd)
If ThePositions.Top < 60 Then
Call RepositionBelowToolBar(Me.hwnd)
End If
End Sub

Thats it! nothing fancy but it works fine.






Shane Brennan

'-----------------------

' Emails: shanebrennan@postmaster.co.uk


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top