Why MDI Child Forms Ignore CenterParent
FormStartPosition.CenterParent only works for modal dialogs (ShowDialog).
MDI children are hosted inside an internal MdiClient control, and Windows does not apply parent-based centering logic to them. That means you must manually calculate the position before showing the form.
MDI Parent Code: Opening a Centered Child Form
The OpenForm method assigns the MDI parent, switches to manual positioning, and calculates the centered coordinates:
Imports System.Windows.Forms
Public Class MDIParent1
Public Sub OpenForm(frm As Form)
' Opens a child form centered inside the MDI parent.
' MDI children ignore StartPosition.CenterParent, so we must position manually.
' Assign this form as the MDI parent
frm.MdiParent = Me
' Required so our manual Left/Top values are used
frm.StartPosition = FormStartPosition.Manual
' Center the child form inside the MDI parent window.
' Note: Using Me.Width/Height centers relative to the full MDI form,
' not the MdiClient area, but works well for most layouts.
frm.Left = (Me.Width - frm.Width) \ 2
frm.Top = (Me.Height - frm.Height) \ 2
' Display the form
frm.Show()
End Sub
' Runs when the MDI parent loads
Private Sub MDIParent1_Load(sender As Object, e As EventArgs) Handles Me.Load
' Store a reference globally if other forms need access to the MDI parent
Globals.MDIParent = Me
' Create the initial child form and open it centered
Dim frm As New Form1
OpenForm(frm)
End Sub
End Class
This gives you a consistent, predictable way to open any child form in the center of the MDI window.
Child Form Code: Opening Additional Forms
Child forms can open other child forms by retrieving the MDI parent reference and calling OpenForm again:
Public Class Form1
' Holds a reference to the MDI parent so this form
' can open additional child forms through it.
Dim mfrmParent As MDIParent1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
' Retrieve the MDI parent instance that was stored globally.
' This avoids needing to walk the form hierarchy to find the parent.
mfrmParent = CType(Globals.MDIParent, MDIParent1)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Create a new child form instance
Dim frm As New Form2
' Ask the MDI parent to open it using the same centering logic
mfrmParent.OpenForm(frm)
End Sub
End Class
This keeps all child-form creation consistent and avoids duplicating centering logic across multiple forms.
Wrapping Up
MDI applications still have their place in line-of-business software, but they come with quirks—like ignoring CenterParent. By centralizing your child-form creation in a single OpenForm method, you get predictable behavior, cleaner code, and a reusable pattern that works across your entire application. Whether you're opening the first form on startup or launching additional forms from inside other children, this approach keeps everything centered and consistent.