问题
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