How to maximize window in XNA

爷,独闯天下 提交于 2019-12-01 08:54:34

问题


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 to set the width and height of the window, but that's not quite the same. I also need to do this without going full screen. I just want a normal maximized window.


回答1:


@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;



回答2:


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




回答3:


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;



回答4:


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);



回答5:


_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.



来源:https://stackoverflow.com/questions/11786640/how-to-maximize-window-in-xna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!