6

How to get display resolution in XNA/Monogame ? I tried these on my monitor (1600x900):

The below give me 800,600

//1.
GraphicsDevice.DisplayMode.Width
GraphicsDevice.DisplayMode.Height

//2.
GraphicsDeviceManager graphics = new GraphicsDeviceManager(this);
graphics.GraphicsDevice.DisplayMode.Width
graphics.GraphicsDevice.DisplayMode.Height

//3.
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height

//4.
foreach (DisplayMode dm in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
{
    Console.WriteLine(dm.Width);
    Console.WriteLine(dm.Height);
}
dimitris93
  • 4,155
  • 11
  • 50
  • 86

2 Answers2

19
_ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
_ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

extra references: System.Drawing , System.Windows.Forms

dimitris93
  • 4,155
  • 11
  • 50
  • 86
0

If the application start in full screen, this may work:

Vector2 resolution = new Vector2(GraphicsDevice.Viewport.Width,GraphicsDevice.Viewport.Height);
ViNi
  • 63
  • 1
  • 8
  • you cant start it in full screen if you cant calculate the screens size in the first place, i answered my own question btw – dimitris93 Dec 05 '14 at 14:24
  • Nice, you could try this as well: http://msdn.microsoft.com/en-us/library/bb195024.aspx – ViNi Dec 05 '14 at 14:34
  • `this.graphics.IsFullScreen = true;` this actually doesn't work, some people say its xbox only – dimitris93 Dec 05 '14 at 14:48
  • it does work. You have to do this: graphics = new GraphicsDeviceManager(this); graphics.IsFullScreen = true; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 960; graphics.ApplyChanges(); – John Lord Aug 17 '19 at 21:56