由于 VB.NET 中用于定位表单的内置功能并不总是适合使用,因此我尝试让我的 sub 来做到这一点。
但是我错过了一些东西...
Public Sub form_center(ByVal frm As Form, Optional ByVal parent As Form = Nothing)
Dim x As Integer
Dim y As Integer
Dim r As Rectangle
If Not parent Is Nothing Then
r = parent.ClientRectangle
x = r.Width - frm.Width + parent.Left
y = r.Height - frm.Height + parent.Top
Else
r = Screen.PrimaryScreen.WorkingArea
x = r.Width - frm.Width
y = r.Height - frm.Height
End If
x = CInt(x / 2)
y = CInt(y / 2)
frm.StartPosition = FormStartPosition.Manual
frm.Location = New Point(x, y)
End Sub
如果已定义,如何让此子将表单正确放置在屏幕中间或其他表单中?