C#: Get complete desktop size?

前端 未结 9 2106
梦谈多话
梦谈多话 2020-11-27 16:40

How do I find out the size of the entire desktop? Not the \"working area\" and not the \"screen resolution\", both of which refer to only o

9条回答
  •  萌比男神i
    2020-11-27 16:48

    I think the best way to get the "real" screen-size, is to get the values directly from the video-controller.


        using System;
        using System.Management;
        using System.Windows.Forms;
    
        namespace MOS
        {
            public class ClassMOS
            {
                public static void Main()
                {
                    try
                    {
                        ManagementObjectSearcher searcher = 
                            new ManagementObjectSearcher("root\\CIMV2", 
                            "SELECT * FROM Win32_VideoController"); 
    
                        foreach (ManagementObject queryObj in searcher.Get())
                        {
                            Console.WriteLine("CurrentHorizontalResolution: {0}", queryObj["CurrentHorizontalResolution"]);
                            Console.WriteLine("-----------------------------------");
                            Console.WriteLine("CurrentVerticalResolution: {0}", queryObj["CurrentVerticalResolution"]);
                        }
                    }
                    catch (ManagementException e)
                    {
                        MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
                    }
                }
            }
    }
    

    This should do the job ;) Greetings ...

提交回复
热议问题