Question centered the component

kenmax

New member
Joined
Mar 6, 2009
Messages
1
Programming Experience
Beginner
Commonly if I maximized my form. It'll look like this
Untitled-1-1.jpg


And now, i just want to ask a simple question..
How to centered all those components if i maximized it??

thanks alot...
 
Group the controls in a container control, for example a Panel, then use the Forms Resize event where you calculate where to position the Panel in relation to the forms ClientSize and the Panels Size. Here is a code example:
VB.NET:
Public Sub CenterParent(ByVal c As Control)
    If c Is Nothing OrElse c.Parent Is Nothing Then Return
    Dim p As New Point(c.Parent.ClientSize - c.Size)
    c.Location = New Point(p.X \ 2, p.Y \ 2)
End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    Me.CenterParent(Me.Panel1)
End Sub
 
Back
Top