2

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?

Erik A
  • 31,639
  • 12
  • 42
  • 67
arm
  • 49
  • 2
  • 2
  • 4

1 Answers1

2

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?

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • I am beginner in access i didn't got what to do! would you please explain more what i have to do? – arm Apr 05 '13 at 07:20
  • @arm I have added an example to my answer. – Gord Thompson Apr 05 '13 at 10:02
  • tanks, it was very helpful. but in my form some objects get disappear when resizing the form,for example a text box correctly goes to center but it's label get disappear! i didn't find the problem! is there a way to writ this cod for all the objects in one statement? – arm Apr 05 '13 at 18:11
  • 1
    @arm **re: disappearing label** -- It could be that your textbox is being moved on top of the label and hiding it. Moving the textbox this way will not move its label with it (unlike when dragging a textbox in design view and having its associated label move at the same time). **re: move all objects in one statement** -- No, you'll have to move each object individually. – Gord Thompson Apr 05 '13 at 18:58