Exemplo n.º 1
0
 // The Refresh method updates the values to reflect the current
 // situation.  Run Refresh if you have changed the number or
 // configuration of monitors in the display.
 public static void Refresh()
 {
     Display.VirtualLeft   = Display.GetSystemMetrics(SystemMetric.SM_XVIRTUALSCREEN);
     Display.VirtualTop    = Display.GetSystemMetrics(SystemMetric.SM_YVIRTUALSCREEN);
     Display.VirtualWidth  = Display.GetSystemMetrics(SystemMetric.SM_CXVIRTUALSCREEN);
     Display.VirtualHeight = Display.GetSystemMetrics(SystemMetric.SM_CYVIRTUALSCREEN);
     Display.MonitorCount  = Display.GetSystemMetrics(SystemMetric.SM_CMONITORS);
     Display.MonitorsHaveSameDisplayFormat = (Display.GetSystemMetrics(SystemMetric.SM_SAMEDISPLAYFORMAT) != 0);
     Display.Screens = new ScreenInfoCollection();
     Display.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
                                 new EnumMonitorsDelegate(EnumMonitorsProc), IntPtr.Zero);
 }
Exemplo n.º 2
0
        public ScreenInfoCollection GetScreenInfoCollection()
        {
            var monitorInfoCollection = new ScreenInfoCollection();

            EnumDisplayMonitors(
                IntPtr.Zero,
                IntPtr.Zero,
                delegate(IntPtr hMonitor, IntPtr hdcmonitor, ref RECT lprcMonitor, IntPtr dwData)
            {
                var monitorInfoEx  = new MONITORINFOEX();
                monitorInfoEx.Size = Marshal.SizeOf(monitorInfoEx);
                var result         = GetMonitorInfo(hMonitor, ref monitorInfoEx);
                if (result)
                {
                    var displayScale = GetScreenDisplayScale(hMonitor);
                    var screenInfo   = new ScreenInfo(hMonitor, monitorInfoEx, displayScale);
                    monitorInfoCollection.Add(screenInfo);
                }
                return(true);
            },
                IntPtr.Zero);

            return(monitorInfoCollection);
        }