This SHOULD be a very simple question but after lots of searching there seems to be no working example anywhere. I just want my XNA window to start off maximized. I know how
_graphics = new GraphicsDeviceManager(this);
DisplayMode displayMode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;
this._graphics.PreferredBackBufferFormat = displayMode.Format;
this._graphics.PreferredBackBufferWidth = (int)(displayMode.Width);
this._graphics.PreferredBackBufferHeight = (int)(displayMode.Height);
Sort of works for me but not quite, you'll understand once you try. I mean, it's not perfect and I'm sure there's a better way but for prototyping this should work - or maybe with some tweaking you could get what you need.
Set the IsFullScreen
property of the graphics device manager to true.
http://msdn.microsoft.com/en-us/library/bb195024(v=xnagamestudio.10).aspx
//from the above msdn sample
graphics = new GraphicsDeviceManager( this );
content = new ContentManager( Services );
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
graphics.PreferMultiSampling = false;
graphics.IsFullScreen = true;
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphicsdevicemanager.isfullscreen(v=xnagamestudio.10).aspx
You can add a reference to System.Windows.Forms and System.Drawing (However, You will need to type the namespaces out, Because of ambiguities)
Use the following code after base.Initialize
Form form = (Form)Form.FromHandle(Window.Handle);
form.Location = Point(0, 0);
form.Size = Screen.PrimaryScreen.WorkingArea.Size;
@Cyral has the closest answer so far, but it's still not quite what you want. To maximize a Windows Form, you use the WindowState property:
var form = (Form)Form.FromHandle(Window.Handle);
form.WindowState = FormWindowState.Maximized;
Others have covered the step of maximizing automatically, but to enable the actual maximize button so the user can do it when desired, do this in the Game constructor:
Window.AllowUserResizing = true;
Depending on how you want the game to behave when resizing begins and ends, perhaps pause the game, you may need to handle some of these events.
Form form = (Form)Form.FromHandle(Window.Handle);
form.ResizeBegin += new EventHandler(form_ResizeBegin);
form.ResizeEnd += new EventHandler(form_ResizeEnd);
form.LocationChanged += new EventHandler(form_LocationChanged);