basically what I want to do is center a 800×600 game inside a maximized window. so if the resolution is 1280×1024, there will be a large border, but if the resolution is 800×600 it will take up the whole screen
this is in the Initialize method, it makes the game window fullscreen with a fixed 3d border but the client area also resizes to full screen
Form gameWindowForm = (Form)sys.Form.FromHandle(this.Window.Handle);
gameWindowForm.FormBorderStyle = FormBorderStyle.Fixed3D;
gameWindowForm.Text = "";
gameWindowForm.ControlBox = false;
gameWindowForm.WindowState = sys.FormWindowState.Maximized;
I have tried setting preferred back buffer, clientbounds size, viewport and displaymode. No matter what I try to resize I either can’t because it is read only or it doesn’t change anything.
Any help?
If you want to customise the window layout, perhaps try the official WinForms sample. There’s no “official” way in XNA to mess with the client area within the window.
However if all you want to do is center the rendering region within the window, then you should be able to do that just by setting the viewport at the beginning of each frame, like so:
(Note that this code will fail if your window gets too small and the viewport exceeds the screen size – so you’ll want to check for that and respond – maybe by using a smaller viewport.)
Just keep in mind that
GraphicsDevice.Clearwill clear the entire backbuffer in XNA 4.0, not just the viewport (so instead just draw a flat-coloured rectangle across the viewport).