55

How can I adjust the size of the window in XNA.

Default it starts in a 800x600 resolution.

Alex B
  • 24,678
  • 14
  • 64
  • 87

4 Answers4

70

As of XNA 4.0 this property is now found on the GraphicsDeviceManager. Ie. this code would go in your Game's constructor.

graphics = new GraphicsDeviceManager(this);
graphics.IsFullScreen = false;
graphics.PreferredBackBufferHeight = 340;
graphics.PreferredBackBufferWidth = 480;

// if changing GraphicsDeviceManager properties outside 
// your game constructor also call:
// graphics.ApplyChanges();
James
  • 1,973
  • 1
  • 18
  • 32
60

I found out that you need to set the

GraphicDevice.PreferredBackBufferHeight = height;
GraphicDevice.PreferredBackBufferWidth = width;

When you do this in the constructor of the game class it works, but when you try do to this outside the constructor you also need to call

GraphicsDevice.ApplyChanges();

Furthermore to have fullscreen (which is not really working correctly while debugging) you can use

if (!GraphicsDevice.IsFullScreen)
   GraphicsDevice.ToggleFullScreen();
pinckerman
  • 4,115
  • 6
  • 33
  • 42
  • 3
    This answer is a bit out of date, so I recommend checking Fuex's answer below. It is mostly the same but the code will compile without any edits. – Vin St. John May 12 '13 at 05:33
-1

You should look at this, http://forums.xna.com/forums/p/1031/107718.aspx.

Nikwin
  • 6,576
  • 4
  • 35
  • 43
-1

This solution works in XNA 3.0. Just put it in your game object's constructor:

// Resize the screen to 1024 x 768.
IntPtr ptr = this.Window.Handle;
System.Windows.Forms.Form form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(ptr);
form.Size = new System.Drawing.Size(1024, 768);

graphics.PreferredBackBufferWidth = 1024;
graphics.PreferredBackBufferHeight = 768;

graphics.ApplyChanges();
pinckerman
  • 4,115
  • 6
  • 33
  • 42
jabs
  • 7
  • 1