I have the below code which I use which includes hiding the taskbar by my form. It works well if there are two screens connected to my computer but if there is only one screen the taskbar shows, I am not sure why?
FormBorderStyle = FormBorderStyle.None;
await Task.Delay(500);
this.WindowState = FormWindowState.Normal;
this.ActiveControl = textBox1;
StartPosition = FormStartPosition.Manual;
Location = new Point(0, 0);
var height = Screen.AllScreens.Max(x => x.WorkingArea.Height + x.WorkingArea.Y);
var width = Screen.AllScreens.Max(x => x.WorkingArea.Width + x.WorkingArea.X);
Size = new Size(width, height);
this.BringToFront();
this.AcceptButton = button1;
this.ControlBox = false;
this.TopMost = true;
this.Size = Size;
Rectangle ru = Rectangle.Union(Screen.AllScreens[0].Bounds , Screen.AllScreens[1].Bounds);
Bounds = ru;
You're getting an "System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'" error because of AllScreens[1] when you only have one screen connected there is only one value in the AllScreen array so index[1] is out of bound.
Change;
To;
Now because you're using a Select you wil only getting AllScreens[0] instead of guessing what indexes well be there this code now also works is you have three monitors or any other configuration of monitors.
Edit
Also, as a small side note if you're trying to block a user from doing anything outside of your program. This will not block them fully actions like pressing the windows key will still bring up the taskbar or give control back to the user.