Export (0) Print
Expand All

How To: Allow the Player to Resize a Game Window

Demonstrates how to let the player resize the game window.

The Complete Sample

The code in this tutorial illustrates the technique described in the text. A complete code sample for this tutorial is available for you to download, including full source code and any additional supporting files required by the sample.

To Add Player Window Resizing to a Game

  1. Derive a class from Game.
  2. Set Game.GameWindow.AllowUserResizing to true, and add an event handler for the ClientSizeChanged event of Game.Window.
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        ...
        this.Window.AllowUserResizing = true;
        this.Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged);
        ...
    }
    
  3. Implement a method to handle the ClientSizeChanged event of Game.Window.
    void Window_ClientSizeChanged(object sender, EventArgs e)
    {
        // Make changes to handle the new window size.            
    }
    

Community Additions

ADD
Show:
© 2014 Microsoft