Access User's Possible Screen Resolutions - C# 2010

感情迁移 提交于 2019-12-13 04:33:10

问题


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.


回答1:


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; 



回答2:


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.



来源:https://stackoverflow.com/questions/3039651/access-users-possible-screen-resolutions-c-sharp-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!