Centering form controls

M

McGeeky

Hi. I am writing some form logic to centre my form controls when a maximised
form is resized. I have a handler for the forms resize event. But when I
inspect the form width in the resize event it is always set to the same
value even when I resize it.

Is there a way to get the current width of the form?

I am using Access 2000. This is the code;

Private Sub Form_Resize()

Debug.Print "current size is " & Me.Width

End Sub

Thank you!

McGeeky
 
D

Danny Lesandrini

There might be a very elegant way to do this, and if so, I'll learn something. For some reason, measuring forms can get tricky.

You can read the forms Width property, but the height is different. It's the sum of the Header, Footer and Detail height ...

lngHeight = Me.Section(acHeader).Height +
Me.Section(acFooter).Height +
Me.Section(acDetail).Height

I've got code I use that does the following to determine exactly how big my whole Access app space is:

Create Global variables for Screen Width & Height
Maximize the current form so it fills the screen
Set the Width and Height variables using Me.InsideWidth and M.InsideHeight
Restore the form and use the variables how you need.

I run this in the Timer() function of a form and usually turn off screen painting. In this code, I have a menu dashboard that
is always as tall as the app, always slammed to the left and is always the same width, cDashboardWidth.

Private Sub Form_Timer()
On Error GoTo Err_Handler

DoCmd.Maximize
g_lngScreenWidth = Me.InsideWidth
g_lngScreenHeight = Me.InsideHeight
g_lngDashboardHeight = g_lngScreenHeight
DoCmd.Restore

DoCmd.Restore
DoCmd.MoveSize 0, 0, cDashboardWidth, g_lngDashboardHeight
Me.TimerInterval = 0

Exit_Here:
DoCmd.Echo True
Exit Sub
Err_Handler:
LogErrorToTable Err.Number, Err.Description, "Form_fmnuContacts", "Form_Timer", Erl
Resume Next
End Sub


Not sure if this helps at all, but it will get you started.
 
M

McGeeky

Thanks for your reply Danny.

I have made some progress on this now. I am using Me.WindowWidth which seems
to give the current window size.

McGeeky
 
M

McGeeky

Ha! Finally done it. My form controls now stay centred in the form no matter
what I resize it to.
 
M

McGeeky

Thanks Peter. I checked out your centering product but it wasn't what I
needed.

I have cracked it now anyway; all my form controls stay centred as I resize
the form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Form resize event 4
subform resize??? 4
Form_Resize is Not Triggered When Form is Moved 12
Resizing controls 1
Private Sub Form_Resize() 1
On Resize 4
Form Height 1
Putting a button at the corner of a form 2

Top