Tutorials Icon

Tutorials > MonoGame - Switch between Full Screen and Windowed

MonoGame - Switch between Full Screen and Windowed

By Stephen Armstrong // March 3, 2020


Change your game to display in fullscreen or windowed modes.

MonoGame starts in a normal (bordered) window by default, but it’s easy to toggle between different modes.

The following C# code will show you how to switch between fullscreen and windowed display modes in a MonoGame project.

Change windowed modes

Add the following method to your Game1:

void ControlWindowedMode(bool becomeBorderless)
{
    Window.IsBorderless = becomeBorderless;
    graphics.ApplyChanges();
}

Calling this method with a false bool will set the game to a normal (bordered) window.

Calling this method with a true bool will set the game to a borderless window.

Please note that this method will do nothing if called when the game is in fullscreen.

Toggle fullscreen

Add the following method to your Game1:

void ControlFullScreenMode(bool becomeFullscreen)
{
    graphics.IsFullScreen = becomeFullscreen;
    graphics.ApplyChanges();
}

Calling this method with a false bool will disable fullscreen.

Calling this method with a true bool will set it to fullscreen.

Testing

To test that these methods work, go to Game1.cs’ Update() cycle and add the following code:

// Press/Hold F1 to become a borderless window.
if (Keyboard.GetState().IsKeyDown(Keys.F1))
{
    ControlWindowedMode(true);
}
// Press/Hold F2 to become a normal window.
if (Keyboard.GetState().IsKeyDown(Keys.F2))
{
    ControlWindowedMode(false);
}
// Press/Hold F3 to enter fullscreen.
if (Keyboard.GetState().IsKeyDown(Keys.F3))
{
    ControlFullScreenMode(true);
}
// Press/Hold F4 to exit fullscreen.
if (Keyboard.GetState().IsKeyDown(Keys.F4))
{
    ControlFullScreenMode(false);
}

Run your game and you can use the F1, F2, F3, and F4 keys to switch between windowed and fullscreen modes.

< Go back

Return to top of page

Article Icon

Welcome to Industrian.net!

On this website you'll find more information about our games, and also some tutorials for you to start making games of your own! You can also follow us on various social platforms!