运行期间屏幕上的中心表单

时间:2017-08-29 08:53:55

标签: vb.net

我正在使用vb.net,我想到的是点击一个按钮,当前表单会展开,它将以屏幕为中心。

我已经想出如何扩展表单,但我无法将其放在屏幕上。

我尝试过使用此代码,但这不是我想要的。

Dim Width As Integer = Screen.PrimaryScreen.Bounds.Width
Dim Height As Integer = Screen.PrimaryScreen.Bounds.Height

Me.Location = New Point(Height / 2, Width / 2)

或其他:Me.Location = New Point(Width / 2, Height/ 2)

甚至试过这个:Me.StartPosition = FormStartPosition.Center

1 个答案:

答案 0 :(得分:1)

使用.CentreToScreen()

像这样:

  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.Size = New System.Drawing.Size(400, 650)
    Me.CenterToScreen()
End Sub