private void MaximizeWindow(bool maximize)
        {
            if (!MaximizeBox || !ControlBox)
            {
                return;
            }

            _maximized = maximize;

            if (maximize)
            {
                var monitorHandle = MonitorFromWindow(Handle, MonitorDefaulttonearest);
                var monitorInfo   = new Monitorinfoex();
                GetMonitorInfo(new HandleRef(null, monitorHandle), monitorInfo);
                _previousSize     = Size;
                _previousLocation = Location;
                Size     = new Size(monitorInfo.rcWork.Width(), monitorInfo.rcWork.Height());
                Location = new Point(monitorInfo.rcWork.left, monitorInfo.rcWork.top);
            }
            else
            {
                Size     = _previousSize;
                Location = _previousLocation;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the size of the monitor holding the window
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public static Size MonitorSize(Window window)
        {
            // Get handle for nearest monitor to this window
            var wih = new WindowInteropHelper(window);
            var hMonitor = UnsafeNativeMethods.MonitorFromWindow(wih.Handle, 2);

            // Get monitor info
            var monitorInfo = new Monitorinfoex();
            monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);
            UnsafeNativeMethods.GetMonitorInfo(new HandleRef(window, hMonitor), monitorInfo);

            return new Size(monitorInfo.rcMonitor.Right, monitorInfo.rcMonitor.Bottom);
        }
 public static extern bool GetMonitorInfo(HandleRef hmonitor, [In, Out] Monitorinfoex info);