2

I'm trying to create a borderless form with custom close and minimize button. However it seems that when setting the border to none and window state to maximized will cause the form to hide the taskbar which is not what I want. Note that I'm using windows 7, I've read a couple of answers here and elsewhere nothing seems to work for me, the taskbar is always getting hidden. A couple of things tried out with no luck are listed below:

  • this.WindowState = FormWindowState.Maximized; this.FormBorderStyle = FormBorderStyle.None; this.TopMost = true;

  • Screen screen = Screen.FromPoint(this.Location); this.Size = screen.WorkingArea.Size; this.Location = Point.Empty;

  • this.Bounds = Screen.PrimaryScreen.WorkingArea;

ancdev
  • 207
  • 10
  • 18

5 Answers5

7

I guess this is what you are looking for

this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size;

check this

Community
  • 1
  • 1
Ivan
  • 71
  • 1
  • 4
  • You should use `Screen.FromControl(this)` instead of `Screen.PrimaryScreen` if the user has multiple screens. – Joscplan Sep 09 '15 at 01:23
1

Here is the simplest solution:

this.Width = Screen.PrimaryScreen.Bounds.Width;
this.Height = Screen.PrimaryScreen.Bounds.Height - 40;

this.Location = new Point();

this.StartPosition = FormStartPosition.Manual;

In this example, I suppose that taskbar is visible, and that taskbar is positioned at bottom. You can read this question/answers How can I determine programmatically whether the Windows taskbar is hidden or not? in order to extend my example with automatic detection of taskbar status.

And here is example how to determine taskbar size: How do I get the taskbar's position and size?.

At my resolution, taskbar size is 40.

Community
  • 1
  • 1
Danilo Vulović
  • 2,983
  • 20
  • 31
  • It seems to work, however (-40) is not always applicable, isn't this determined the by the screen resolution?.. Meaning in some cases 40 wouldn't be enough or vice versa. – ancdev Oct 09 '12 at 22:52
  • 1
    Yes, as I wrote. You need to use approach from shared link to determine size of taskbar. – Danilo Vulović Oct 09 '12 at 22:53
  • 1
    Ok it worked fine. One more thing had to cover is that if the user changed resolution while the system is running, had to add a maximize button to fix window again. Thanks. – ancdev Oct 09 '12 at 23:10
  • Be carefull to use Screen.PrimaryScreen, you should detect whitch screen is actual to a window. – Viacheslav Smityukh Oct 09 '12 at 23:22
1

When you set the form border style to none the form will hide the taskbar. To get around this you have to set the the MaximumSize of the form manually. If windows auto-hides the taskbar the form will cover even the hidden taskbar! To get around this reduce the max size height by one pixel (if your taskbar is in the bottom)!

        Me.MaximumSize = New Size(My.Computer.Screen.WorkingArea.Size.Width, _
                                  My.Computer.Screen.WorkingArea.Size.Height - 1)
Dirk
  • 11
  • 1
0

This seems to be the behaviour you're telling the form to exhibit - if you tell it to be topmost and set the bounds explicitly to the whole screen it will cover the task bar. (This is often done in POS and touchscreen applications)

Try just setting FormWindowState.Maximized and not telling the bounds to fill the whole screen.

Rob Hardy
  • 1,821
  • 15
  • 15
0

Just set start position to manual and also property MaximizeBox to true. when form is loaded and maximized by clicking maximized button you can have task bar!