【发布时间】:2017-12-21 18:20:31
【问题描述】:
如何在控制台应用程序中获得屏幕分辨率(如果可能)?
在Forms 我可以使用:
int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;
但我正在寻找专门的控制台方式。
所以解决我的问题的方法是Marc-Antoine Jutras提出的。我需要int 值所以我是这样的:
int height = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
int width = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
【问题讨论】:
-
对于控制台应用程序没有特定的方法可以做到这一点,因为控制台毕竟只是一个窗口;您可以只引用
System.Windows.Forms并使用与以前相同的代码。 -
@Clint 没有。有可能
-
您可以使用GDI。刚刚检查过 - 就像一个魅力。要使用答案中的 sn-p,请添加
include System.Drawing; using System.Runtime.InteropServices; -
@Sergey.quixoticaxis.Ivanov 好吧。但是有很多方法可以给猫剥皮。这不是一种“特定于控制台的方式”。当然,您可以 p/invoke 来获取它,但是为什么要在添加引用时麻烦您呢?
-
@Clint 因为 PresentationFoundation 很重,Forms 也很重,都带来一堆依赖。
标签: c#