Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#
Article

Full Screen Mode in C#

Rate me:
Please Sign up or sign in to vote.
2.08/5 (20 votes)
23 Jan 20051 min read 233.5K   4.5K   42   22
An easy way to enter into full screen mode.

Introduction

There are situations where you want your application to go into a full screen presentation mode. This mode usually covers the whole desktop with a black background and the application sits in the middle of the screen.

How to do it?

I am presenting a simple solution using C#. In this application, I have made the application accept F11 as the toggle key to go into full screen mode and to revert back to its original state. To accomplish that, I set the KeyPreview property of the form to true.

When the F11 key is pressed, I create another form that has its WindowState property set to Maximized, the background color is set to Black.

The trick here is to set the main application's form's owner to that of the second form. By setting the Owner property, Windows will display the application on top of the black background window. The last thing to do is to set the FormBorderStyle of the main form to None.

C#
private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
  {
   if ( e.KeyData == Keys.F11)
   {
      if (_bFullScreenMode == false)
      {
           Form2 f = new Form2();
           this.Owner = f;
           this.FormBorderStyle = FormBorderStyle.None;
           this.Left = (Screen.PrimaryScreen.Bounds.Width/2 - this.Width/2);
           this.Top = (Screen.PrimaryScreen.Bounds.Height/2 - this.Height/2);
           f.Show();
           _bFullScreenMode = true;
           f.KeyUp +=new KeyEventHandler(Form1_KeyUp);
      }
      else
      {
           Form f = this.Owner;
           this.Owner = null;
           f.Close();
     
           this.FormBorderStyle = FormBorderStyle.Sizable;
           _bFullScreenMode = false;
      }
   }
  }

Conclusion

Here is just a simple method for an application to enter to a full screen mode without writing a lot of resizing code in the main application.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow to resize a fullscreen background image Pin
Gaurav Panchal13-May-13 13:37
Gaurav Panchal13-May-13 13:37 
GeneralMy vote of 1 Pin
gioakim18-Oct-10 23:49
gioakim18-Oct-10 23:49 
QuestionWhat about multiple monitors Pin
Dave Midgley21-Sep-10 1:25
Dave Midgley21-Sep-10 1:25 
GeneralMy 5 cents [modified] Pin
Andrew17-Nov-09 10:32
Andrew17-Nov-09 10:32 
GeneralRe: My 5 cents [modified] Pin
wvd_vegt4-Nov-11 0:33
professionalwvd_vegt4-Nov-11 0:33 
Hi
This code works much better (had problems with the code in the article).

I rewrote it a bit so it's a property (which i find somewhat cleaner and allows F11 code like: FullScreen=!FullScreen).

C#
private Boolean fFullScreen = false;
private FormBorderStyle _borderStyle;
private Rectangle _bounds;
private bool _topMost;

/// <summary>
/// Modified from comments at http://www.codeproject.com/KB/cs/fullscreenmode.aspx
/// </summary>
public Boolean FullScreen
{
    get
    {
        return fFullScreen;
    }
    set
    {
        if (fFullScreen != value)
        {
            // update state flag
            fFullScreen = value;

            switch (FullScreen)
            {
                case false:
                    // Restore previous settings
                    this.FormBorderStyle = _borderStyle;
                    this.Bounds = _bounds;
                    this.TopMost = _topMost;
                    this.menuStrip1.Visible = true;

                    break;

                case true:
                    // Save current settings
                    _borderStyle = this.FormBorderStyle;
                    _bounds = this.Bounds;
                    _topMost = this.TopMost;

                    // Full screen
                    this.FormBorderStyle = FormBorderStyle.None;
                    Screen screen = Screen.FromControl(this); // get screen for form
                    this.Bounds = screen.Bounds;
                    this.TopMost = true;
                    this.menuStrip1.Visible = false;

                    break;
            }
        }
    }
}

wvd_vegt

GeneralMy vote of 1 Pin
Jimmanuel26-Feb-09 4:50
Jimmanuel26-Feb-09 4:50 
GeneralThere is already a built in propety for this! Pin
Yazeed Hamdan1-Jan-09 4:58
Yazeed Hamdan1-Jan-09 4:58 
NewsI prefer: Pin
Sidneys14-Sep-08 9:13
Sidneys14-Sep-08 9:13 
GeneralRe: I prefer: Pin
Vercas29-Oct-10 6:20
Vercas29-Oct-10 6:20 
GeneralFlashing Forms Issue in CF2.0 Pin
Hani0721-Sep-07 4:17
Hani0721-Sep-07 4:17 
QuestionNot really fullscreen mode application? Pin
Gunn31713-Feb-06 3:28
Gunn31713-Feb-06 3:28 
AnswerRe: Not really fullscreen mode application? Pin
Rob Magee10-May-06 10:21
Rob Magee10-May-06 10:21 
GeneralRe: Not really fullscreen mode application? Pin
bebangs27-Jun-06 22:48
bebangs27-Jun-06 22:48 
GeneralRe: Not really fullscreen mode application? Pin
bebangs28-Jun-06 1:04
bebangs28-Jun-06 1:04 
GeneralRe: Not really fullscreen mode application? Pin
nonnb6-Feb-07 18:19
nonnb6-Feb-07 18:19 
GeneralSecond once on F11 !!! Pin
CSharpJSharp24-Dec-05 0:45
CSharpJSharp24-Dec-05 0:45 
GeneralRe: Second once on F11 !!! Pin
Gunn31713-Feb-06 3:23
Gunn31713-Feb-06 3:23 
GeneralKeyCapture Pin
eggie523-Jan-05 15:41
eggie523-Jan-05 15:41 
GeneralRe: KeyCapture Pin
slingman23-Jan-05 16:34
slingman23-Jan-05 16:34 
GeneralRe: KeyCapture Pin
eggie523-Jan-05 17:13
eggie523-Jan-05 17:13 
GeneralRe: KeyCapture Pin
slingman24-Jan-05 10:15
slingman24-Jan-05 10:15 
GeneralRe: KeyCapture Pin
eggie524-Jan-05 12:57
eggie524-Jan-05 12:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.