0

我需要调整表单大小并使其占据屏幕的 80%,目前,这就是我所拥有的

 Dim Sw As Integer = CInt(Screen.PrimaryScreen.Bounds.Width * 0.8)
        Dim Sh As Integer = CInt(Screen.PrimaryScreen.Bounds.Height * 0.8)
        Dim nTaskBarHeight As Integer = Screen.PrimaryScreen.Bounds.Bottom - Screen.PrimaryScreen.WorkingArea.Bottom
        Me.Size = New Size(Sw, Sh - nTaskBarHeight)

但它不居中,有人可以帮忙吗?

4

2 回答 2

1

您只更改大小;也改变 Me.Location;仍然需要为它做一些数学运算:)

类似的问题,答案很好: Visual Basic 中屏幕右下角的位置表格

于 2011-12-07T12:04:48.383 回答
0

解决方案

Dim Sw As Integer = CInt(Screen.PrimaryScreen.WorkingArea.Width * 0.8)
Dim Sh As Integer = CInt(Screen.PrimaryScreen.WorkingArea.Height * 0.8)
Me.Size = New Size(Sw, Sh)
Dim x As Integer = Screen.PrimaryScreen.WorkingArea.Width \ 2 - Me.Width \ 2
Dim y As Integer = Screen.PrimaryScreen.WorkingArea.Height \ 2 - Me.Height \ 2
Me.Location = New Point(x, y)
于 2011-12-07T12:15:44.317 回答