如何获取显示分辨率(屏幕尺寸)

本文关键字:屏幕 分辨率 显示 获取 何获取 | 更新日期: 2023-09-27 18:33:23

如何在XNA/Monogame中获取显示分辨率?我在显示器(1600x900)上尝试了这些:

下面给我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);
}

如何获取显示分辨率(屏幕尺寸)

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

额外参考: System.Drawing , System.Windows.Forms

如果应用程序全屏启动,这可能有效:

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