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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easiest way to align the form??

Status
Not open for further replies.

kkgusta

MIS
Nov 10, 2005
42
NZ
Hi there,
I am wonder is there any easier way to re arrange the position of all object in a form based on the size of the screen.
 
For example I design my interface in a 17" screen and all object will be relocated to the middle of the screen if I open it in a 19" screen
 
Thank ZmrAbdulla fro you example. it is very help. But what about if i just need to move teh form to the center of the screen without resizing it?
 
And what about the AutoCenter property of the Form object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This is the module and code I was using. However it doesn't work properly if i maximize the form. Is anyone here know how to fix it ?


Private Sub Form_Load()


Me.Width = Me.WindowWidth

Call MOvetoCenter(Forms.menu_new, Me.Width, Me.Line5.Width)



End Sub





Sub MOvetoCenter(From As Access.Form, Fullwidth As Integer, MyWidth As Integer)

Dim Ctrl As Control
Dim AddWidth As Integer
AddWidth = 0


If MyWidth >= Fullwidth Then

Exit Sub

Else

AddWidth = (Fullwidth - MyWidth) / 2

For Each Ctrl In From.Controls
'MsgBox (Ctrl.Left)
Ctrl.Left = Ctrl.Left + AddWidth
'MsgBox (Ctrl.Left)
Next Ctrl

End If

End Sub
 
kkgusta,
In Access 2000 you can use [tt]InsideWidth[/tt] instead of [tt]WindowWidth[/tt], and I would do it [tt]OnResize[/tt]
Code:
Private Sub Form_Resize()
'[s]Me.Width = Me.WindowWidth[/s]
Call MOvetoCenter(Forms.menu_new, Me.InsideWidth, Me.Line5.Width)
End Sub

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
The reason i put the code in form_load is becasue I wantedo set the the correct location for all the objects when the form is loaded and it will not change until the user close the form. I also wanted maximize the form everytime loaded. However the code I am using is unable to give me the exact max window width.
 
kkgusta,
My brain cannot compute tonight so I'm struggling with your logic a little (I'm not sure what your doing with [tt]Forms.menu_new[/tt]). Here is a fresh bit of code that moves controls when the form resizes (including maximizing) relative to their design time location.

Code:
Private gStartingWidth As Long

Private Sub Form_Open(Cancel As Integer)
gStartingWidth = Me.Width
DoCmd.Maximize
End Sub

Private Sub Form_Resize()
RePositionControls Me.InsideWidth
gStartingWidth = Me.InsideWidth
End Sub

Sub RePositionControls(NewWidth As Long)
On Error Resume Next
Dim ctlCurrent As Control
For Each ctlCurrent In Me.Controls
  ctlCurrent.Left = ctlCurrent.Left + ((NewWidth - gStartingWidth) \ 2)
Next ctlCurrent
End Sub

Note: If you resize the form too small it will throw the control alignment ([tt].Left[/tt])out of whack.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Did PHV's suggestion not work?

What about the Move method?

Me.Move Left:=0, Top:=0, Width:=400, Height:=300

you can do your math calculations,
based on screen & form size, to get the actual
coordinates for the Move properties.
 
PHV suggestion is working well But is not exactly what I need. I am current using the auto center function to allign my screen. I will try CautionMP's code later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top