C#: Get complete desktop size?

前端 未结 9 2132
梦谈多话
梦谈多话 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
    慢半拍i (楼主)
    2020-11-27 17:02

    Get the Size of a virtual display without any dependencies

    public enum SystemMetric
    {
        VirtualScreenWidth = 78, // CXVIRTUALSCREEN 0x0000004E 
        VirtualScreenHeight = 79, // CYVIRTUALSCREEN 0x0000004F 
    }
    
    [DllImport("user32.dll")]
    public static extern int GetSystemMetrics(SystemMetric metric);
    
    public static Size GetVirtualDisplaySize()
    {
        var width = GetSystemMetrics(SystemMetric.VirtualScreenWidth);
        var height = GetSystemMetrics(SystemMetric.VirtualScreenHeight);
    
        return new Size(width, height);
    }
    

提交回复
热议问题