0

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?

Smith
  • 5,765
  • 17
  • 102
  • 161

2 Answers2

1

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

Community
  • 1
  • 1
Anton
  • 1,409
  • 1
  • 19
  • 37
0

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)
Smith
  • 5,765
  • 17
  • 102
  • 161