您的位置:首页 > 编程语言 > VB

VB.Net 设置子窗口在父窗口居中显示

2013-01-28 13:42 323 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: