Private Function SetLocation(ByVal insForm As Form) As Point
'Screen.AllScreens[0]是获取当前显示器设备窗口的第一个
Dim insScreen As Screen = Screen.AllScreens(0)
If (Not Me.OwnerForm Is Nothing) Then
'获取控件父窗口的屏幕
insScreen = Screen.FromControl(Me)
End If
'当前屏幕的宽度 - 子页面的宽度
Dim width As Integer = (insScreen.WorkingArea.Width - insForm.Width)
'当前屏幕的高度 - 子页面的高度
Dim height As Integer = (insScreen.WorkingArea.Height - insForm.Height)
'居中
Dim x As Integer = (insScreen.WorkingArea.X + CInt(Math.Round(CDbl((CDbl(width) / 2)))))
Dim y As Integer = (insScreen.WorkingArea.Y + CInt(Math.Round(CDbl((CDbl(height) / 2)))))
'启动模式
insForm.StartPosition = FormStartPosition.Manual
'返回
Return New Point(x, y)
End Function
VB.Net 设置子窗口在父窗口居中显示
最新推荐文章于 2023-06-06 18:41:37 发布