Back to monogame.net
Show / Hide Table of Contents

Class GameWindow

The system window used by a Game.

Inheritance
Object
GameWindow
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: Microsoft.Xna.Framework
Assembly: MonoGame.Framework.dll
Syntax
public abstract class GameWindow

Constructors

GameWindow()

Create a GameWindow.

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

Declaration
public virtual bool AllowAltF4 { get; set; }
Property Value
Type Description
Boolean

AllowUserResizing

Indicates if users can resize this GameWindow.

Declaration
public abstract bool AllowUserResizing { get; set; }
Property Value
Type Description
Boolean

ClientBounds

The client rectangle of the GameWindow.

Declaration
public abstract Rectangle ClientBounds { get; }
Property Value
Type Description
Rectangle

CurrentOrientation

The display orientation on a mobile device.

Declaration
public abstract DisplayOrientation CurrentOrientation { get; }
Property Value
Type Description
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.

Declaration
public abstract IntPtr Handle { get; }
Property Value
Type Description
IntPtr

IsBorderless

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

Declaration
public virtual bool IsBorderless { get; set; }
Property Value
Type Description
Boolean
Exceptions
Type Condition
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.

Declaration
public abstract Point Position { get; set; }
Property Value
Type Description
Point

ScreenDeviceName

The name of the screen the window is currently on.

Declaration
public abstract string ScreenDeviceName { get; }
Property Value
Type Description
String

Title

Gets or sets the title of the game window.

Declaration
public string Title { get; set; }
Property Value
Type Description
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(Boolean)

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

Declaration
public abstract void BeginScreenDeviceChange(bool willBeFullScreen)
Parameters
Type Name Description
Boolean willBeFullScreen

Indicates what mode the game will switch to.

Create(Game, Int32, Int32)

Declaration
public static GameWindow Create(Game game, int width, int height)
Parameters
Type Name Description
Game game
Int32 width
Int32 height
Returns
Type Description
GameWindow

EndScreenDeviceChange(String)

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

Declaration
public void EndScreenDeviceChange(string screenDeviceName)
Parameters
Type Name Description
String screenDeviceName

Name of the screen to move the window to.

EndScreenDeviceChange(String, Int32, Int32)

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

Declaration
public abstract void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
Parameters
Type Name Description
String screenDeviceName

Name of the screen to move the window to.

Int32 clientWidth

The new width of the client rectangle.

Int32 clientHeight

The new height of the client rectangle.

OnActivated()

Called when the window gains focus.

Declaration
protected void OnActivated()

OnDeactivated()

Called when the window loses focus.

Declaration
protected void OnDeactivated()

OnOrientationChanged()

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

Declaration
protected void OnOrientationChanged()

OnPaint()

Declaration
protected void OnPaint()

OnScreenDeviceNameChanged()

Called when ScreenDeviceName changed. Raises the ScreenDeviceNameChanged event.

Declaration
protected void OnScreenDeviceNameChanged()

SetSupportedOrientations(DisplayOrientation)

Declaration
protected abstract void SetSupportedOrientations(DisplayOrientation orientations)
Parameters
Type Name Description
DisplayOrientation orientations

SetTitle(String)

Set the title of this window to the given string.

Declaration
protected abstract void SetTitle(string title)
Parameters
Type Name Description
String title

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.

Declaration
public event EventHandler<EventArgs> ClientSizeChanged
Event Type
Type Description
EventHandler<EventArgs>

FileDrop

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

Declaration
public event EventHandler<FileDropEventArgs> FileDrop
Event Type
Type Description
EventHandler<FileDropEventArgs>
Remarks

This event is only supported on desktop platforms.

KeyDown

Buffered keyboard KeyDown event.

Declaration
public event EventHandler<InputKeyEventArgs> KeyDown
Event Type
Type Description
EventHandler<InputKeyEventArgs>

KeyUp

Buffered keyboard KeyUp event.

Declaration
public event EventHandler<InputKeyEventArgs> KeyUp
Event Type
Type Description
EventHandler<InputKeyEventArgs>

OrientationChanged

Raised when CurrentOrientation changed.

Declaration
public event EventHandler<EventArgs> OrientationChanged
Event Type
Type Description
EventHandler<EventArgs>

ScreenDeviceNameChanged

Raised when ScreenDeviceName changed.

Declaration
public event EventHandler<EventArgs> ScreenDeviceNameChanged
Event Type
Type Description
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.

Declaration
public event EventHandler<TextInputEventArgs> TextInput
Event Type
Type Description
EventHandler<TextInputEventArgs>
Remarks

This event is only supported on desktop platforms.

Back to top Generated by DocFX