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