resize and center form to 80% of screen
-
29-10-2019 - |
Question
I need to resize my form and make it occupy 80% of the screen, currently, this is what i have
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)
But it does not center, can anyone help?
Solution 2
The solution
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)
OTHER TIPS
You are changing only Size; change Me.Location too; still need do some math for it :)
similar question with great answer: Position form at the bottom right corner of the screen in visual basic
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow