Full Screen mode:
Hide the taskbar and set the Work Area
Maximize the form and set the border style of the form
Full Screen Form code public partial class FrmFullScreen: Form {Boolean m_IsFullScreen = false; // mark whether full screen Rectangle rectOld = Rectangle. empty; public FrmFullScreen () {InitializeComponent ();} /// <summary> /// Click Event of the full screen button /// </summary> /// <param name = "sender"> </param> // <param name = "e"> </param> private void btnFullScreen_Click (object sender, eventArgs e) {m_IsFullScreen =! M_IsFullScreen; // click full screen once, and then click Restore. SetFormFullScreen (m_IsFullScreen); this. suspendLayout (); if (m_IsFullScreen) // full screen {this. windowState = FormWindowState. maximized; this. formBorderStyle = FormBorderStyle. none;} else // restore TODO: The restored form should be consistent with the size before full screen {this. windowState = FormWindowState. normal; this. formBorderStyle = FormBorderStyle. sizable;} this. resumeLayout (false);} // <summary> // full screen shortcut. F11 is equivalent to a single-host button. Esc Jian, exit full screen if it is full screen. /// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </ param> private void btnFullScreen_KeyDown (object sender, keyEventArgs e) {if (e. keyCode = Keys. f11) {btnFullScreen. optional mclick (); e. handled = true;} else if (e. keyCode = Keys. escape) // exit full screen on the esc keyboard {if (m_IsFullScreen) {e. handled = true; SetFormFullScreen (false); this. windowState = FormWindowState. normal; // restore this. formBorderStyle = FormBorderStyle. sizable ;}}/// <summary> /// set full screen or cancel full screen /// </summary> /// <param name = "fullscreen"> true: full Screen false: Restore </param> /// <param name = "rectOld"> when set, this parameter returns the original size, use this parameter to set recovery </param> // <returns> setting result </returns> public Boolean SetFormFullScreen (Boolean fullscreen )//, ref Rectangle rectOld {Rectangle rectOld = Rectangle. empty; Int32 hwnd = 0; hwnd = FindWindow ("Shell_TrayWnd", null); // obtain the taskbar handle if (hwnd = 0) return false; if (fullscreen) // full Screen {ShowWindow (hwnd, SW_HIDE); // hide the taskbar SystemParametersInfo (SPI_GETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE); // get the Screen range Rectangle rectFull = Screen. primaryScreen. bounds; // full screen SystemParametersInfo (SPI_SETWORKAREA, 0, ref rectFull, SPIF_UPDATEINIFILE); // form full screen display} else // restore {ShowWindow (hwnd, SW_SHOW ); // display the taskbar SystemParametersInfo (SPI_SETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE); // form restore} return true;} # region user32.dll [DllImport ("user32.dll ", entryPoint = "ShowWindow")] public static extern Int32 ShowWindow (Int32 hwnd, Int32 nCmdShow); public const Int32 SW_SHOW = 5; public const Int32 SW_HIDE = 0; [DllImport ("user32.dll", EntryPoint = "SystemParametersInfo")] private static extern Int32 SystemParametersInfo (Int32 uAction, Int32 uParam, ref Rectangle lpvParam, Int32 fuWinIni ); public const Int32 SPIF_UPDATEINIFILE = 0x1; public const Int32 SPI_SETWORKAREA = 47; public const Int32 SPI_GETWORKAREA = 48; [DllImport ("user32.dll", EntryPoint = "FindWindow")] private static extern Int32 FindWindow (string lpClassName, string lpWindowName); # endregion}