BrightnessTray.WindowPositioning.GetWorkingArea C# (CSharp) Method

GetWorkingArea() public static method

Returns the working area of the monitor that intersects most with the specified rectangle. If no monitor can be found, the closest monitor to the rectangle is returned.
public static GetWorkingArea ( Rect rectangle ) : Rect
rectangle System.Windows.Rect The rectangle that is located on the monitor whose working area should be returned.
return System.Windows.Rect
        public static Rect GetWorkingArea(Rect rectangle)
        {
            NativeMethods.RECT rect = (NativeMethods.RECT)rectangle;
            IntPtr monitorhandle = NativeMethods.MonitorFromRect(ref rect, NativeMethods.MONITOR_DEFAULTTONEAREST);

            NativeMethods.MONITORINFO monitorinfo = new NativeMethods.MONITORINFO();
            monitorinfo.cbSize = (uint)Marshal.SizeOf(monitorinfo);

            bool result = NativeMethods.GetMonitorInfo(monitorhandle, ref monitorinfo);
            if (!result)
                throw new Exception("Failed to retrieve monitor information.");

            return monitorinfo.rcWork;
        }