How to properly handle orientation changes for a MonoGame Windows Project

Hey everyone,

I have a game that supports touchscreen, keyboard, and mouse. It includes a MonoGame Windows 10 UWP project and a MonoGame Windows Project.

When the game is played in tablet mode, I want to lock the screen orientation in Landscape or Landscape-flipped.

On the UWP build I can accomplish this by setting the Package.appxmanifest property Supported Rotation. Everything works fine.

On the Windows build, there is no Package.appxmanifest. I tried setting the property GraphicsDeviceManager.SupportedOrientations in the base game class’s constructor as seen below. However, this does not prevent the game from switching between portrait and landscape mode when in tablet mode.

graphics = new GraphicsDeviceManager(this)
{
    SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight
};
graphics.ApplyChanges();

My goal is to keep a build of the game that does not require UWP/Windows Store. For this build, if the computer happens to be a 2 in 1, I want to user to be able to play the game in tablet mode if they desire. However, the game mechanics and graphics lend very poorly to portrait mode.

So, what is the proper way to handle switching screen orientation when using the MonoGame Windows Project? Or is this just not possible with the framework?

Thanks.

-Brett


EDIT:
Using MonoGame 3.7.0.1014 with VS2017
Behaviour observed on a Windows 10 x64 machine.

I spent some time looking over the MonoGame source code. It appears the reason MonoGame Windows Project do not allow limiting orientation changes on a 2 in 1 is because the WinForms implementation of GameWindow.SetSupportedOrientations is an empty function.

I did a quick google search for how to limit Orientation Changes with WinForms. It seems this isn’t well supported by WinForms. Some people will set the system level registry property to prevent orientation change, but this would affect all open applications. So using this approach, you wouldn’t be able to minimize the game, switch to another app, and change to portrait mode.

class WinFormsGameWindow : GameWindow, IDisposable
{
    . . .

    protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
    {
    }

    . . .
}

If I end up compiling both a UWP and standard Windows build of the game, perhaps the standard Windows game will have to just not be tablet enabled? Or the user will just have to deal with wonky resolution changes if they accidently rotate their 2 in 1 in tablet mode until they get it back into landscape mode?

Thanks,
-Brett