ABANDOND ACOUNT ABANDOND ACOUNT - 1 year ago 82
Vb.net Question

Keeping panels centerd vb.net

I have two panels in VB.Net. The parent panel

(panel1)
is docked to the form meaning it resizes when the form resizes.

The child panel
(panel2)
is supposed to be at the centre of panel1, however when its parent or the form resize, the centre is not kept by panel2.

In short how can I keep panel2 at the centre of panel1 at all times?

I use VB.net.

Answer Source

Try something like this:

Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    Panel2.Top = (Panel1.Height - Panel2.Height) / 2
    Panel2.Left = (Panel1.Width - Panel2.Width) / 2
End Sub