47
votes

how do i get the width and height of the entire screen in XNA?

3

3 Answers

61
votes

This seems to be it (just googled for "xna screen width height" myself):

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width
80
votes

Empirically I've found that in XNA 4.0 I need to use

GraphicsDevice.Viewport.Width
GraphicsDevice.Viewport.Height

when running windowed mode, as I find

GraphicsDevice.DisplayMode.Width
GraphicsDevice.DisplayMode.Height 

gives me the resolution of the entire screen.

Hopefully this helps someone else out.

3
votes

GraphicsDevice.Viewport.Bounds - this returns Rectangle2D and it has parameters Width and Height.