48

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

RCIX
  • 38,647
  • 50
  • 150
  • 207

3 Answers3

80

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.

zawata
  • 172
  • 6
Eddie Parker
  • 4,770
  • 3
  • 35
  • 43
  • 5
    That was actually what i was asking for; window width/height is a different thing. – RCIX Nov 11 '10 at 06:13
62

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

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width
Paul Turner
  • 38,949
  • 15
  • 102
  • 166
Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
3

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

ikillapps
  • 146
  • 7