XNA - Get Current Screen Resolution

Jpin picture Jpin · Jan 21, 2012 · Viewed 21.8k times · Source

Is it possible to get the current desktop screen resolution?

I have a few minor settings in my XNA game one of which is screen resolution. What I want to do is blank out a screen resolution option if it is larger than the current desktop resolution supports.

Answer

Nic Foster picture Nic Foster · Jan 21, 2012

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width and .Height will give you the device's current resolution.

Game.GraphicsDevice.Viewport has height and width variables you can query, that will give you the resolution of your viewport. The viewport is usually the size of the window, but that's not guaranteed.

Window.ClientBounds.Width and .Height will give you the resolution of your game window.