keep 3 controls centered on a form
If you have 3 controls (and the code can be altered to accomodate more), you can use the code below to center one control, and size the two on the sides to fill the gaps:
VB Code:
Me.centerControl.Location = New Point((Me.Width / 2) - (Me.centerControl.Width / 2), (Me.Height / 2) - (Me.centerControl.Height / 2))
Me.leftControl.Width = Me.centerControl.Location.X - 2
Me.rightControl.Width = Me.leftControl.Width - 2
i subtracted 2 from the widths to give some 'breathing room'
pretty simple..Thanks to RobDog for the first line of code
Re: keep 3 controls centered on a form
Can't you do all this with the Anchor property?
Re: keep 3 controls centered on a form
probably so but using the code above, it resizes in real-time when a user resizes the container control.
just tossing in my little bit of knowledge i gained :)
Re: keep 3 controls centered on a form
Fair enough, but Anchor is real time too.
:thumb: