2017-08-29 77 views
0

我正在使用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

使用.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 
+0

沒有工作:(它只是擴大了我的形式,並留在它的位置。 –

+0

你想如何擴展它? – Subaz

+0

這裏是我擴展的代碼:'Me.Size = New System.Drawing.Size(400,650)',而原始格式爲400 x 450,所以只有它的長度將擴大 –