how to auto center objects in a form in access 200

2019-07-19 05:33发布

问题:

I do not know in designing forms I set objects in center of and set the properity to auto center, but in form view when maximize the form objects go to the top left of the form, Can anyone help me,Please?

回答1:

Access forms have an On Resize event where you can adjust the horizontal location of various controls on the form by manipulating their .Left properties based on the .Width properties of the form itself.

For example, say I have a form with a Command Button named Button0. To keep it (more or less) centered horizontally when the window is resized, I can use the following code in the Form's On Resize event:

Private Sub Form_Resize()
'' adjust the horizontal position of the Command0 button
Me.Command0.Left = (Me.InsideWidth - Me.Command0.Width) / 2
End Sub

Note:

For Access 2007 and later you could also use control layouts. For details on how to use them for centering, see the related question here:

How to Dynamically keep controls centered (relative position) on an MS Access form?