MonoGame: Switch between Full Screen and Windowed
By Stephen Armstrong // March 3rd, 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
, , , and keys to switch between windowed and fullscreen modes.