title: How to use the escape key to control whether a form is fullscreen or not
body: <p>I am attempting to make a form in visual studio using the windows form application and designer, but when I try using the escape key to maximise/minimise and remove/add the border it does not cover all of the taskbar.</p>
  
  <p>I am simply testing the functionality of being able to enter and exit fullscreen for any forms I might make in the future, so far I have tried nothing besides the code pictured, and placing the code in the case selection as a separate subroutine.</p>
  
  <pre><code>Public Sub FullscreenEnterExit(ByVal sender As Object, ByVal d As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
      Select Case d.KeyValue
          Case Keys.Escape
              If fullscreen = False Then
                  Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
                  Me.ClientSize = New System.Drawing.Size(1920, 1080)
                  Me.Controls.Add(Me.PictureBox1)
                  Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
                  Me.MaximumSize = New System.Drawing.Size(1920, 1080)
  
                  Me.Name = "window"
                  Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
                  Me.Text = "Form1"
                  Me.TopMost = True
                  Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
                  CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
                  Me.ResumeLayout(False)
                  fullscreen = True
              ElseIf fullscreen = True Then
                  Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
                  Me.ClientSize = New System.Drawing.Size(1920, 1080)
                  Me.Controls.Add(Me.PictureBox1)
                  Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
                  Me.MaximumSize = New System.Drawing.Size(1920, 1080)
  
                  Me.Name = "window"
                  Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
                  Me.Text = "Form1"
                  Me.TopMost = True
                  Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
                  CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
                  Me.ResumeLayout(False)
                  fullscreen = False
              End If
      End Select
  End Sub
  </code></pre>
  
  <p>I would post images of how the fullscreen looks but you need 10 reputation.
  it is maximised but and covers everything but about 3/4 of the taskbar.
  Help would be much appreciated.</p>