访问用户可能的屏幕分辨率 - C# 2010

发布于 2024-09-05 05:47:12 字数 76 浏览 1 评论 0原文

预先感谢您的帮助。

我想知道如何访问用户电脑上可用的屏幕分辨率。我想获取所有可用分辨率的列表,并确定用户当前运行的分辨率。

Thanks in advance for your help.

I am wondering how I might go about accessing the screen resolutions available on a user's PC. I would like to get a list of all available resolutions and also determine what the user is current running at.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我相信您可以对 User32.dll 中的 EnumDisplaySettings api 调用进行 PInvoke 调用。

[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings (string deviceName, int modeNum, ref DEVMODE devMode );

请参阅此处示例。

您当然会遇到双显示器系统的复杂情况,但要获取当前屏幕,您可以做

System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width

我假设您正在谈论可执行文件而不是 ASP.Net 应用程序,但如果您需要 Javascript 中的屏幕尺寸,您可以可以使用屏幕对象。

screen.width; screen.height; screen.colorDepth; 

I believe you can make a PInvoke call to EnumDisplaySettings api call in User32.dll.

[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings (string deviceName, int modeNum, ref DEVMODE devMode );

See example here.

You'll of course run into complications with dual-monitor systems, but to get the current screen you can do

System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width

I assumed you were talking about an executable and not an ASP.Net app, but if you need the screen size in Javascript, you can use the screen object.

screen.width; screen.height; screen.colorDepth; 
无悔心 2024-09-12 05:47:12

您可以使用 Microsoft.Win32 RegestryKey 类从注册表中获取当前屏幕尺寸。

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\...

我会在那里寻找你想要的东西,但我不会弄乱他们在那里的任何设置。

You could use the Microsoft.Win32 RegestryKey class to fetch the current screen size from the registry.

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\...

I'd hunt around there to find what you want, but I wouldn't mess with whatever settings they have in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文