📅  最后修改于: 2022-03-11 14:48:52.229000             🧑  作者: Mango
Public Shared Sub CenterForm(ByVal frm As Form, Optional ByVal parent As Form = Nothing)
'' Note: call this from frm's Load event!
Dim r As Rectangle
If parent IsNot Nothing Then
r = parent.RectangleToScreen(parent.ClientRectangle)
Else
r = Screen.FromPoint(frm.Location).WorkingArea
End If
Dim x = r.Left + (r.Width - frm.Width) \ 2
Dim y = r.Top + (r.Height - frm.Height) \ 2
frm.Location = New Point(x, y)
End Sub