Reputation: 10154
I have a VB.NET WinForm program in MS VS2017 on MS Windows 10, that has a restricted width, but that should maximize in height the same as any normal Windows application. I have multiple monitors, of different sizes, which seems to be messing with how the application determines the desktop's height. I should note, that my task-bar is set to not expand across the second screen, but only appear on the primary screen (this does not seem to affect other Windows applications behavior though).
I am using the following code in the Move
event handler (I tried overriding WndProc
too, but no luck) but the form maximizes behind the task-bar on the primary screen, i.e. it takes up the full screen height, where it should take up the full screen height minus the task-bar height. It does however, maximize to the correct height on the secondary screen.
Private Sub form1_Move(sender As Object, e As EventArgs) _
Handles MyBase.Move
Me.MaximumSize = New Size(Me.MaximumSize.Width, _ 'fixed width
My.Computer.Screen.Bounds.Height) 'screen height
End Sub
Today I tried changing the line to:
Me.MaximumSize = New Size(Me.MaximumSize.Width, _ 'fixed width
My.Computer.Screen.FromControl(Me).WorkingArea.Height) 'screen height
But this now results in more complex, but still incorrect behavior! (Not full height on the secondary screen). I also tried using SystemInformation.VirtualScreen.Height
, but again, no luck
What is correct way of managing to get the correct height?
Here is an image two of the issues described, the left is the primary monitor, with the form maximizing with a height that places part of it behind the task-bar, the right is the secondary monitor with the maximized height not being high enough to fill the screen that doesn't have the task-bar. As described above, some code ended up also having the form not even meeting the task-bar when maximized on the primary monitor. Basically I just want it to maximize just like any other application, correctly on either monitor, with or without a task-bar, but with a restricted width.
Upvotes: 2
Views: 1639
Reputation: 134
Using this will give you the max height with the taskbar
SystemParameters.WorkArea.Height
Also this post may help full screen mode, but don't cover the taskbar
Upvotes: 0
Reputation: 91965
Look at the documentation for WM_GETMINMAXINFO
, and however that's exposed in .NET.
You might also want to look at WM_WINDOWPOSCHANGING
message.
Both of these allow you to control the size of your window.
Upvotes: 2