Public Sub Center(frm As Form, Optional frmMDI As Variant) Dim ret 'Syntax: Center Form1, [MDIForm1] ret = IsMissing(frmMDI) If ret = False Then frm.Top = (frmMDI.ScaleHeight - frm.Height) / 2 frm.Left = (frmMDI.ScaleWidth - frm.Width) / 2 Else frm.Top = (Screen.Height - frm.Height) / 2 frm.Left = (Screen.Width - frm.Width) / 2 End If End Sub Public Sub CenterChild(Parent As Form, Child As Form) 'Syntax: CenterChild MDIForm1, Form1 Dim iTop As Integer Dim iLeft As Integer If Parent.WindowState <> 0 Then Exit Sub iTop = ((Parent.Height - Child.Height) \ 2) iLeft = ((Parent.Width - Child.Width) \ 2) Child.Move iLeft, iTop ' (This is more efficient than setting Top and Left properties) End Sub Public Sub UnloadAllChildren() Dim vForm As Variant For Each vForm In Forms If Not TypeOf vForm Is MDIForm Then If vForm.MDIChild Then Unload vForm End If End If Next 'vFrom End Sub
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams