You are on page 1of 3

Demonstrates how to resize an active game window.

Complete Sample
The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample. Download GameLoop_Sample.zip.

Adding Window Resizing Functionality


To add player window resizing to a game
1. Derive a class from Game. 2. Set Game.GameWindow.AllowUserResizing to true. 3. Add an event handler for the ClientSizeChanged event of Game.Window.

C#
this.Window.AllowUserResizing = true; this.Window.ClientSizeChanged += new EventHandler<EventArgs>(Window_ClientSizeChanged);

4. Implement a method to handle the ClientSizeChanged event of Game.Window.

C#
void Window_ClientSizeChanged(object sender, EventArgs e) { // Make changes to handle the new window size. }

Game Class
Provides basic graphics device initialization, game logic, and rendering code. Namespace: Microsoft.Xna.Framework Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll) Syntax C#

public class Game : IDisposable

GameWindow.AllowUserResizing Property
Specifies whether to allow the user to resize the game window.

Namespace: Microsoft.Xna.Framework Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll)


Syntax C#
[DefaultValueAttribute(false)] public abstract bool AllowUserResizing { get; set; }

Property Value
true if user resizing is allowed; false otherwise.

GameWindow.ClientSizeChanged Event
Raised when the size of the GameWindow changes. Namespace: Microsoft.Xna.Framework Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll) Syntax C#

public event EventHandler<EventArgs> ClientSizeChanged

Game.Window Property
Other Versions

Gets the underlying operating system window.

Namespace: Microsoft.Xna.Framework Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll)


Syntax

C#
public GameWindow Window { get; }

Property Value
The underlying operating system window.

Demonstrates how to start a game in full-screen mode.

Complete Sample
The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample. Download FullScreenWindows.zip.

Creating a Full-Screen Game


To create a full-screen game
1. Derive a class from Game. 2. After creating the GraphicsDeviceManager, set its PreferredBackBufferWidth and

PreferredBackBufferHeight to the desired screen height and width. 3. Set IsFullScreen to true. C#
this.graphics.PreferredBackBufferWidth = 480; this.graphics.PreferredBackBufferHeight = 800; this.graphics.IsFullScreen = true;

You might also like