C # full screen form function

Source: Internet
Author: User

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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.