Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.net Borderless Form Maximize over Taskbar

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.

like image 800
Jarron Avatar asked Sep 21 '26 15:09

Jarron


2 Answers

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.

like image 127
Hans Passant Avatar answered Sep 27 '26 00:09

Hans Passant


Use the "working area" of the screen:

    Me.Bounds = Screen.GetWorkingArea(Me)
like image 41
Idle_Mind Avatar answered Sep 27 '26 00:09

Idle_Mind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!