3 c#
如何在控制台应用程序中获取屏幕分辨率(如果可能)?
在Forms我可以使用:
int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;
Run Code Online (Sandbox Code Playgroud)
但我正在寻找专门的控制台方式。
所以解决我的问题的方法是由Marc-Antoine Jutras提出的。我需要int价值观,所以我是这样的:
int height = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
int width = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
Run Code Online (Sandbox Code Playgroud)
小智 6
ManagementObjectSearcher mydisplayResolution = new ManagementObjectSearcher("SELECT CurrentHorizontalResolution, CurrentVerticalResolution FROM Win32_VideoController");
foreach (ManagementObject record in mydisplayResolution.Get())
{
Console.WriteLine("-----------------------Current Resolution---------------------------------");
Console.WriteLine("CurrentHorizontalResolution - " + record["CurrentHorizontalResolution"]);
Console.WriteLine("CurrentVerticalResolution - " + record["CurrentVerticalResolution"]);
}
Run Code Online (Sandbox Code Playgroud)