How to maximize window in XNA

后端 未结 5 2028
离开以前
离开以前 2021-01-14 22:35

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

相关标签:
5条回答
  • 2021-01-14 22:54
    _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.

    0 讨论(0)
  • 2021-01-14 23:04

    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

    0 讨论(0)
  • 2021-01-14 23:07

    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;
    
    0 讨论(0)
  • 2021-01-14 23:08

    @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;
    
    0 讨论(0)
  • 2021-01-14 23:17

    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);
    
    0 讨论(0)
提交回复
热议问题