How to get display resolution (screen size)?

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

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

Share:
21,114
dimitris93
Author by

dimitris93

MSc in Computer Science

Updated on July 05, 2022

Comments

  • dimitris93
    dimitris93 almost 2 years

    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);
    }
    
  • dimitris93
    dimitris93 over 9 years
    you cant start it in full screen if you cant calculate the screens size in the first place, i answered my own question btw
  • ViNi
    ViNi over 9 years
    Nice, you could try this as well: msdn.microsoft.com/en-us/library/bb195024.aspx
  • dimitris93
    dimitris93 over 9 years
    this.graphics.IsFullScreen = true; this actually doesn't work, some people say its xbox only
  • John Lord
    John Lord over 4 years
    it does work. You have to do this: graphics = new GraphicsDeviceManager(this); graphics.IsFullScreen = true; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 960; graphics.ApplyChanges();