Align objects in the form to the center w/o using anchoring (1 Viewer)

nax009

New member
Local time
Today, 16:32
Joined
Mar 27, 2023
Messages
15
First, my customer wanted me to make a navigation menu. Then, they wanted to align to the center like figure no. 2. I tried to use anchoring but it didn't work for me and I also tried to put the form into a sub-form but I don't see the way to make them to the center either. Anyone have a solution?

Figure No.1:
1698480527054.png


Figure No.2:
1698480577764.png
 

Josef P.

Well-known member
Local time
Today, 11:32
Joined
Feb 2, 2023
Messages
826
The easiest way is to use the anchors.
But you can also react on Form.Resize and center via VBA code.

Code:
Private Sub Form_Resize()
   CenterControl Me.ctlTest
End Sub

Private Sub CenterControl(ByVal ctl As Control)

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

End Sub
 

Attachments

  • CenterControl.zip
    20.9 KB · Views: 58

nax009

New member
Local time
Today, 16:32
Joined
Mar 27, 2023
Messages
15
The easiest way is to use the anchors.
But you can also react on Form.Resize and center via VBA code.

Code:
Private Sub Form_Resize()
   CenterControl Me.ctlTest
End Sub

Private Sub CenterControl(ByVal ctl As Control)

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

End Sub
IT WORKS! Thanks!
 

Users who are viewing this thread

Top Bottom