C # form Full screen feature

Source: Internet
Author: User

Recently a friend asked me to get him a full-screen application, such as the bank's number-picking program interface. So I've been searching the web for some ways to implement it.

How do you implement full-screen display in C # applications?
The effect is like Windows comes with a screen saver and a lot of games, no matter whether you set the "keep taskbar in front of other windows" does not display the taskbar

Implementation method One

Find some simple ways to implement online:

this. FormBorderStyle = Formborderstyle.none;     // set the form to no border style this. WindowState = formwindowstate.maximized;    //

Then set the form's position and size, for example: width=1024 height=768 left=0 top=0, etc. size value

Put the above two lines of code directly into the Form1_Load method, you can, relatively simple, I do not post code.

Reference Source: http://blog.csdn.net/friendan/article/details/7350570

============================================================

Implementation Method Two

Call the system's API functions, such as the FindWindow and ShowWindow functions in User32.dll, with the following code:

[DllImport ("user32.dll", EntryPoint ="ShowWindow")]         Public Static externInt32 ShowWindow (Int32 hwnd, Int32 ncmdshow); [DllImport ("user32.dll", EntryPoint ="FindWindow")]        Private Static externInt32 FindWindow (stringLpclassname,stringLpwindowname);

The code is as follows:

usingSystem;usingSystem.Windows.Forms;usingSystem.Drawing;usingSystem.Runtime.InteropServices;namespacefullscr{ Public Partial classform1:form {Boolean M_isfullscreen=false;//Mark whether full screen         PublicForm1 () {InitializeComponent (); }        Private voidForm1_Load (Objectsender, EventArgs e) {        }        /// <summary>        ///Click event for full screen button/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidButton1_Click (Objectsender, EventArgs e) {M_isfullscreen=!m_isfullscreen;//Click once full screen, then click Restore.              This.            SuspendLayout (); if(M_isfullscreen)//full screen, executed in a specific order{setformfullscreen (m_isfullscreen);  This. FormBorderStyle =Formborderstyle.none;  This. WindowState =formwindowstate.maximized;  This. Activate ();//            }            Else//restore, execute in a specific order-form state, form border, set taskbar and work area            {                 This. WindowState =Formwindowstate.normal;  This. FormBorderStyle =formborderstyle.sizable;                Setformfullscreen (M_isfullscreen);  This.            Activate (); }             This. ResumeLayout (false); }        /// <summary>          ///set fullscreen or this cancels fullscreen/// </summary>          /// <param name= "fullscreen" >true: Full screen false: Recovery</param>          /// <param name= "Rectold" >when set, this parameter returns the original size, which is restored with this parameter set</param>          /// <returns>Set Results</returns>           PublicBoolean Setformfullscreen (Boolean fullscreen)//, ref Rectangle Rectold{Rectangle Rectold=Rectangle.empty; Int32 hwnd=0; HWND= FindWindow ("Shell_traywnd",NULL);//get the handle to the taskbar            if(hwnd = =0)return false; if(fullscreen)//Full Screen{ShowWindow (hwnd, sw_hide);//Hide Task barSystemParametersInfo (Spi_getworkarea,0,refRectold, Spif_updateinifile);//Get screen RangeRectangle rectfull = Screen.PrimaryScreen.Bounds;//Full Screen rangeSystemParametersInfo (Spi_setworkarea,0,refRectfull, Spif_updateinifile);//form Full Screen display            }            Else//Restore{ShowWindow (hwnd, sw_show);//Show taskbarSystemParametersInfo (Spi_setworkarea,0,refRectold, Spif_updateinifile);//form Restore            }            return true; }        #regionUser32.dll Public ConstInt32 Spif_updateinifile =0x1;  Public ConstInt32 Spi_setworkarea = -;  Public ConstInt32 Spi_getworkarea = -;  Public ConstInt32 sw_show =5;  Public ConstInt32 Sw_hide =0; [DllImport ("user32.dll", EntryPoint ="ShowWindow")]         Public Static externInt32 ShowWindow (Int32 hwnd, Int32 ncmdshow); [DllImport ("user32.dll", EntryPoint ="FindWindow")]        Private Static externInt32 FindWindow (stringLpclassname,stringlpwindowname); [DllImport ("user32.dll", EntryPoint ="SystemParametersInfo")]        Private Static externInt32 SystemParametersInfo (Int32 uaction, Int32 Uparam,refRectangle Lpvparam, Int32 fuWinIni); #endregion    }}


Reference Source: http://www.cnblogs.com/ArcScofield/archive/2013/01/02/Form_Fullscreen.html

C # form Full screen feature

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.