wheels53
wheels53

Reputation: 739

How to obtain the maximum screen resolution that a monitor supports using C#

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);
        }

Upvotes: 1

Views: 4678

Answers (3)

deepi
deepi

Reputation: 1081

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;

Upvotes: 2

Digicoder
Digicoder

Reputation: 1875

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.

Upvotes: 3

Related Questions