问题
I need to obtain the Maximum supported screen resolution of a monitor, not the current resolution which is easy. Any help would be appreciated.
Edit: This is the updated solution that worked for me.
public Size GetMaximumScreenSizePrimary()
{
var scope = new System.Management.ManagementScope();
var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");
using (var searcher = new System.Management.ManagementObjectSearcher(scope, q))
{
var results = searcher.Get();
UInt32 maxHResolution = 0;
UInt32 maxVResolution = 0;
foreach (var item in results)
{
if ((UInt32)item["HorizontalResolution"] > maxHResolution)
maxHResolution = (UInt32)item["HorizontalResolution"];
if ((UInt32)item["VerticalResolution"] > maxVResolution)
maxVResolution = (UInt32)item["VerticalResolution"];
}
log.Debug("Max Supported Resolution " + maxHResolution + "x" + maxVResolution);
}
return new Size(maxHResolution, maxVResolution);
}
回答1:
Get the results from the Management Scope.
var scope = new System.Management.ManagementScope();
var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");
using (var searcher = new System.Management.ManagementObjectSearcher(scope, q))
{
var results = searcher.Get();
foreach (var item in results)
{
Console.WriteLine(item["Caption"]);
}
}
For more information about what information is available, refer to the CIM_VideoControllerResolution page.
回答2:
Obtain newWidth & newHeight of screen resolution as below and use them where u required
Screen scr = Screen.PrimaryScreen;
int newWidth = scr.Bounds.Width;
int newHeight = scr.Bounds.Height;
回答3:
Use primary screen property
http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.primaryscreen.aspx
Regards.
来源:https://stackoverflow.com/questions/7537078/how-to-obtain-the-maximum-screen-resolution-that-a-monitor-supports-using-c-shar