0

I thought this would take 5 minutes. Spent 3 hours and haven't figured it out...

I have an MDI application and would like an easy way for the user to make it full screen without maximizing it, so I added a Windows/Full Screen menu option and put in this code to handle it:

    Me.Left = 0
    Me.Top = 0
    Me.Width = Screen.PrimaryScreen.WorkingArea.Width
    Me.Height = Screen.PrimaryScreen.WorkingArea.Height

The problem is this leaves gaps on the left, bottom, and right side. The top is the only screen edge that works as expected - snugged against the top. The others leave about a 1/8" gap to the screen edges, and 1/8" from the task bar at the bottom.

Sure, I could fudge it and hardcode +10 (or whatever) to the height and width, and -5 to the left. But that seems like a kludge (a fudge kludge), and maybe won't be the same for every monitor.

I tried the DPI awareness thing in the manifest, but it made no difference. I also tried Screen.PrimaryScreen.Bounds and Screen.PrimaryScreen.WorkingArea.X / Y, also with no joy.

It really shouldn't be this difficult. Wth?

  • I ended up just hardcoding it until someone provides a better solution. The following worked on my widescreen dev monitor (3440x1440) as well as my VirtualBox in various resolutions (including non-standard oddball ones). Me.Left = -7 Me.Top = 0 Me.Width = Screen.PrimaryScreen.WorkingArea.Width + 14 Me.Height = Screen.PrimaryScreen.WorkingArea.Height + 7 – Coder84 Mar 13 '20 at 11:17
  • [According to this answer, the order of how you set the properties matters.](https://stackoverflow.com/a/16764459/3585500) – ourmandave Mar 13 '20 at 11:19
  • It should be `8 * 2`, not `7 * 2` (but pretty close). That's the invisible border around the Form. When you maximize your Form using normal means, check its Bounds property (you'll see negative values). DpiAwareness is required, if you want to get correct measures. – Jimi Mar 13 '20 at 14:54
  • Win10 gives a window a transparent border. The gap you see. Meant to leave enough room to move the mouse to the window edge so you can resize the window. You need that room. – Hans Passant Mar 14 '20 at 15:48
  • That's a good point Hans. But when I use my code above (using 7 instead of 8, Jimi), then the resizing still works. – Coder84 Mar 15 '20 at 08:49

3 Answers3

0

Try this:

Dim diffW As Integer = Me.Width - Me.ClientSize.Width
Dim diffH As Integer = Me.Height - Me.ClientSize.Height

Me.ClientSize = New Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height - diffH)
Me.Location = New Point(-diffW / 2, 0)
G3nt_M3caj
  • 2,497
  • 1
  • 14
  • 16
  • That works for the edges, but the bottom still has a 1/8" gap. I'm gonna go ahead and just leave it with my hardcoded 7 so the resizing still works. Thanks everyone! – Coder84 Mar 15 '20 at 08:55
0

I´m not quite sure if I understand you correct: You don´t like to have the user to press the maximize button? Instead you try to provide your own "maximize" function?

Ok, sounds strange, but anyway:

Did you already try this:

Screen.PrimaryScreen.WindowState = FormWindowState.Maximized

(sorry, copied from C# code if there is an syntax mayhem)

nabuchodonossor
  • 2,095
  • 20
  • 18
0

I understand it is late but this hack can solve:

for c#

this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;

for vb:

Me.FormBorderStyle = FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
Albert Alberto
  • 801
  • 8
  • 15