21

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.

Martin.
  • 10,494
  • 3
  • 42
  • 68
Jpin
  • 1,527
  • 5
  • 18
  • 27
  • 4
    possible duplicate of [XNA: get screen's width and height](http://stackoverflow.com/questions/1377524/xna-get-screens-width-and-height) – Kieren Johnstone Jan 21 '12 at 17:17

2 Answers2

39

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.

Nic Foster
  • 2,864
  • 1
  • 27
  • 45
  • 1
    Thanks for the reply. I found the answer to be: GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height – Jpin Jan 21 '12 at 23:26
  • 2
    Ah yes, you're right. Viewport gives you the resolution of your game window, which can be smaller than the entire desktop if you're in windowed mode on a PC, whereas CurrentDisplayMode gives you the desktop resolution. I will edit my answer to include those details for future readings. – Nic Foster Jan 22 '12 at 02:42
  • 3
    Viewport can be changed to have a size smaller than the window (ex. splitscreen). I would stick with Window.ClientBounds.Width/Height. – YellPika Jan 22 '12 at 03:11
  • Thanks YellPike, I've added that information to the answer. – Nic Foster Nov 25 '14 at 20:49
9

GraphicsAdapter.SupportedDisplayModes will return a collection of all of the supported aspect ratios. You can then show all of the ratios that are in this collection.

Justin Self
  • 6,137
  • 3
  • 33
  • 48