dimitris93
dimitris93

Reputation: 4273

How to get display resolution (screen size)?

How to get display resolution in XNA/Monogame ? I tried these on my monitor (1600x900):

The below give me 800,600

//1.
GraphicsDevice.DisplayMode.Width
GraphicsDevice.DisplayMode.Height

//2.
GraphicsDeviceManager graphics = new GraphicsDeviceManager(this);
graphics.GraphicsDevice.DisplayMode.Width
graphics.GraphicsDevice.DisplayMode.Height

//3.
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height

//4.
foreach (DisplayMode dm in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
{
    Console.WriteLine(dm.Width);
    Console.WriteLine(dm.Height);
}

Upvotes: 7

Views: 24712

Answers (2)

dimitris93
dimitris93

Reputation: 4273

_ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
_ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

extra references: System.Drawing , System.Windows.Forms

Upvotes: 19

ViNi
ViNi

Reputation: 73

If the application start in full screen, this may work:

Vector2 resolution = new Vector2(GraphicsDevice.Viewport.Width,GraphicsDevice.Viewport.Height);

Upvotes: 0

Related Questions