Centering form controls

S

swas

Hi,

I want to centre a control on a form, regardless of the form or application
size.

I have read many posts on resizing, screen widths, and resolutions but I am
not trying to achieve this.

All I want to do is ensure a control is centered on the form.

I'm not sure what property to use to retrieve the current form screen width
and height, that is correct regardless whether the form and / or application
is maximised or not.


Thanks in advance.


swas
 
M

Marshall Barton

swas said:
I want to centre a control on a form, regardless of the form or application
size.

I have read many posts on resizing, screen widths, and resolutions but I am
not trying to achieve this.

All I want to do is ensure a control is centered on the form.

I'm not sure what property to use to retrieve the current form screen width
and height, that is correct regardless whether the form and / or application
is maximised or not.


Use the form's InsideWidth and InsideHeight properties and
set the control's Left and Top properties.

ctl.Left = (Me.InsideWidth - ctl.Width) / 2
ctl.Top = (Me.InsideHeight - ctl.Height) / 2
 
S

swas

Thanks for that Marshal.

I had already done this and it wasn't working correctly. It has taken me a
while to work out why, and is because I am using a tab control which has
horizontal and vertical anchor settings in Access 2007.

These can't be turned off as far as I can see, hence making the resize event
interfere with the tab control sizing.

Is there any way around this? The code works fine with something like a text
box.


Thanks again.


swas
 
M

Marshall Barton

WOW! This is wierd. I tried setting up a form with a tab
control in A2003 and when I tried to center the tab control
in the Resize event, it went and changed the size of the tab
control without centering it. I mean, what is going on when
I set the Left property and the Width changes? Same thing
happened when I set the Top property and instead the Height
changed??

I almost never use a tab control so I guess I never tried
centering one before. Either my test db is corrupted in
such a way that this is the only manifestation of it or
there is one more really oddball bug with tab controls.
Sorry, but I think you may be SOL.
 
S

swas

Marshall,

Like I said, I'm having the same problem. At least my sanity is (relatively)
confirmed...

I'll work around it one way or another.

Your help is appreciated; you do a lot on these boards.


swas
 

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

Top