Table of Contents

Class GameWindow

Namespace
Microsoft.Xna.Framework
Assembly
MonoGame.Framework.dll

The system window used by a Game.

public abstract class GameWindow
Inheritance
GameWindow
Inherited Members

Constructors

GameWindow()

Create a GameWindow.

protected GameWindow()

Properties

AllowAltF4

Gets or sets a bool that enables usage of Alt+F4 for window closing on desktop platforms. Value is true by default.

public virtual bool AllowAltF4 { get; set; }

Property Value

bool

AllowUserResizing

Indicates if users can resize this GameWindow.

public abstract bool AllowUserResizing { get; set; }

Property Value

bool

ClientBounds

The client rectangle of the GameWindow.

public abstract Rectangle ClientBounds { get; }

Property Value

Rectangle

CurrentOrientation

The display orientation on a mobile device.

public abstract DisplayOrientation CurrentOrientation { get; }

Property Value

DisplayOrientation

Handle

The handle to the window used by the backend windowing service.

For WindowsDX this is the Win32 window handle (HWND). For DesktopGL this is the SDL window handle. For UWP this is a handle to an IUnknown interface for the CoreWindow.

public abstract nint Handle { get; }

Property Value

nint

IsBorderless

Determines whether the border of the window is visible. Currently only supported on the WindowsDX and DesktopGL platforms.

public virtual bool IsBorderless { get; set; }

Property Value

bool

Exceptions

NotImplementedException

Thrown when trying to use this property on a platform other than WinowsDX or DesktopGL.

Position

The location of this window on the desktop, eg: global coordinate space which stretches across all screens.

public abstract Point Position { get; set; }

Property Value

Point

ScreenDeviceName

The name of the screen the window is currently on.

public abstract string ScreenDeviceName { get; }

Property Value

string

Title

Gets or sets the title of the game window.

public string Title { get; set; }

Property Value

string

Remarks

For UWP this has no effect. The title should be set by using the DisplayName property found in the app manifest file.

Methods

BeginScreenDeviceChange(bool)

Called before a game switches from windowed to full screen mode or vice versa.

public abstract void BeginScreenDeviceChange(bool willBeFullScreen)

Parameters

willBeFullScreen bool

Indicates what mode the game will switch to.

EndScreenDeviceChange(string)

Called when a transition from windowed to full screen or vice versa ends, or when the GraphicsDevice is reset.

public void EndScreenDeviceChange(string screenDeviceName)

Parameters

screenDeviceName string

Name of the screen to move the window to.

EndScreenDeviceChange(string, int, int)

Called when a transition from windowed to full screen or vice versa ends, or when the GraphicsDevice is reset.

public abstract void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)

Parameters

screenDeviceName string

Name of the screen to move the window to.

clientWidth int

The new width of the client rectangle.

clientHeight int

The new height of the client rectangle.

OnActivated()

Called when the window gains focus.

protected void OnActivated()

OnDeactivated()

Called when the window loses focus.

protected void OnDeactivated()

OnOrientationChanged()

Called when CurrentOrientation changed. Raises the OnOrientationChanged() event.

protected void OnOrientationChanged()

OnPaint()

protected void OnPaint()

OnScreenDeviceNameChanged()

Called when ScreenDeviceName changed. Raises the ScreenDeviceNameChanged event.

protected void OnScreenDeviceNameChanged()

SetSupportedOrientations(DisplayOrientation)

protected abstract void SetSupportedOrientations(DisplayOrientation orientations)

Parameters

orientations DisplayOrientation

SetTitle(string)

Set the title of this window to the given string.

protected abstract void SetTitle(string title)

Parameters

title string

The new title of the window.

Events

ClientSizeChanged

Raised when the user resized the window or the window switches from fullscreen mode to windowed mode or vice versa.

public event EventHandler<EventArgs> ClientSizeChanged

Event Type

EventHandler<EventArgs>

FileDrop

This event is raised when user drops a file into the game window

public event EventHandler<FileDropEventArgs> FileDrop

Event Type

EventHandler<FileDropEventArgs>

Remarks

This event is only supported on desktop platforms.

KeyDown

Buffered keyboard KeyDown event.

public event EventHandler<InputKeyEventArgs> KeyDown

Event Type

EventHandler<InputKeyEventArgs>

KeyUp

Buffered keyboard KeyUp event.

public event EventHandler<InputKeyEventArgs> KeyUp

Event Type

EventHandler<InputKeyEventArgs>

OrientationChanged

Raised when CurrentOrientation changed.

public event EventHandler<EventArgs> OrientationChanged

Event Type

EventHandler<EventArgs>

ScreenDeviceNameChanged

Raised when ScreenDeviceName changed.

public event EventHandler<EventArgs> ScreenDeviceNameChanged

Event Type

EventHandler<EventArgs>

TextInput

Use this event to user text input.

This event is not raised by noncharacter keys except control characters such as backspace, tab, carriage return and escape. This event also supports key repeat.

public event EventHandler<TextInputEventArgs> TextInput

Event Type

EventHandler<TextInputEventArgs>

Remarks

This event is only supported on desktop platforms.