3

When I maximize my borderless form, the form covers the entire screen including the taskbar, which I don't want it to do. I'm finding it very difficult to find a solution to my problem on the net, all I've come up with is the below code, which displays the taskbar for a short time, but then disappears and the form still takes up the entire screen.

Private Sub TableLayoutPanel1_DoubleClick(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.DoubleClick
    If e.Location.Y < 30 Then
        Me.WindowState = FormWindowState.Maximized
        Me.ControlBox = True
    End If
End Sub

I'm starting to think the only way to solve my problem is to find the screen size height minus the taskbar height to get the form height, but I'm hoping there might be a simpler answer.

Jarron
  • 1,049
  • 2
  • 13
  • 29
  • I'm starting to think the controlbox has no relevance to what I'm trying to do. Just assumed it did because the taskbar would appear for a sec when I put that in my code. – Jarron Jan 30 '15 at 17:37
  • Oh, I also tried code to change the form to have a border, maximize then borderless again, but my form started to have melt down and stopped responding. – Jarron Jan 30 '15 at 17:39

4 Answers4

4

Use the form's Load event to set its maximum size, like this:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.MaximumSize = Screen.FromRectangle(Me.Bounds).WorkingArea.Size
End Sub

Maximizing it now restricts the size to the monitor's working area, which is the monitor size minus the taskbars.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Awesome, so glad there was a simple solution to my problem. Thanks so much, was searching the net for hours and couldn't find this answer. – Jarron Jan 30 '15 at 17:55
2

Use the "working area" of the screen:

    Me.Bounds = Screen.GetWorkingArea(Me)
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
2

You should better do this:

Me.MaximumSize = Screen.FromControl(Me).WorkingArea.Size

Because some users use multiple monitors. So if you use Hans Passant's way, when user maximize application to secondary monitor, application will get primary's monitor working area size and will look awful!!!

Simos Sigma
  • 958
  • 7
  • 29
0

I think this is a better way to solve your problem

  Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Normal
        Me.StartPosition = FormStartPosition.Manual
        With Screen.PrimaryScreen.WorkingArea
            Me.SetBounds(.Left, .Top, .Width, .Height)
        End With
    End Sub
Sandun
  • 101
  • 1
  • 5