Here are your options:
To get the back-buffer size use:
GraphicsDevice.PresentationParameters.Bounds
(for a rectangle) or BackBufferWidth
and BackBufferHeight
.
You want the back-buffer size if you're doing stuff like setting viewports, taking screenshots, etc.
To get the Viewport, use:
GraphicsDevice.Viewport.Bounds
(for a rectangle) or Width
and Height
.
The size of the viewport is what you want to use when you're actually rendering stuff. Any coordinates you pass to SpriteBatch
are in pixel-aligned client space in terms of the viewport: (0,0) for the top left pixel to (width-1,height-1) for the bottom right. If you're doing 3D stuff, projection space goes from (-1,-1) in the bottom left of the viewport to (1,1) in the top right.
You can adjust the size and position of the viewport on screen (for doing effects like split-screen). So, while it is initialised to the size of the back-buffer, it is not necessarily always the same.
If you're doing interface layout stuff, particularly if you will run on the Xbox 360, be aware of Viewport.TitleSafeArea
. This tells you what region is definitely visible on screens that may cut off some of the border.
If, for some reason, you're actually working with the game window itself, use Game.GameWindow.ClientBounds
.