Exemplo n.º 1
0
        internal static void KeepInsideNearestMonitor(this ILayoutElementForFloatingWindow paneInsideFloatingWindow)
        {
            var r = new Win32Helper.RECT();

            r.Left   = (int)paneInsideFloatingWindow.FloatingLeft;
            r.Top    = (int)paneInsideFloatingWindow.FloatingTop;
            r.Bottom = r.Top + (int)paneInsideFloatingWindow.FloatingHeight;
            r.Right  = r.Left + (int)paneInsideFloatingWindow.FloatingWidth;

            uint MONITOR_DEFAULTTONEAREST = 0x00000002;
            uint MONITOR_DEFAULTTONULL    = 0x00000000;

            var monitor = Win32Helper.MonitorFromRect(ref r, MONITOR_DEFAULTTONULL);

            if (monitor == IntPtr.Zero)
            {
                var nearestmonitor = Win32Helper.MonitorFromRect(ref r, MONITOR_DEFAULTTONEAREST);
                if (nearestmonitor != IntPtr.Zero)
                {
                    var monitorInfo = new Win32Helper.MonitorInfo();
                    monitorInfo.Size = Marshal.SizeOf(monitorInfo);
                    Win32Helper.GetMonitorInfo(nearestmonitor, monitorInfo);

                    if (paneInsideFloatingWindow.FloatingLeft < monitorInfo.Work.Left)
                    {
                        paneInsideFloatingWindow.FloatingLeft = monitorInfo.Work.Left + 10;
                    }

                    if (paneInsideFloatingWindow.FloatingLeft + paneInsideFloatingWindow.FloatingWidth >
                        monitorInfo.Work.Right)
                    {
                        paneInsideFloatingWindow.FloatingLeft =
                            monitorInfo.Work.Right - (paneInsideFloatingWindow.FloatingWidth + 10);
                    }

                    if (paneInsideFloatingWindow.FloatingTop < monitorInfo.Work.Top)
                    {
                        paneInsideFloatingWindow.FloatingTop = monitorInfo.Work.Top + 10;
                    }

                    if (paneInsideFloatingWindow.FloatingTop + paneInsideFloatingWindow.FloatingHeight >
                        monitorInfo.Work.Bottom)
                    {
                        paneInsideFloatingWindow.FloatingTop =
                            monitorInfo.Work.Bottom - (paneInsideFloatingWindow.FloatingHeight + 10);
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void OnActivated(object sender, EventArgs e)
 {
     base.Activated -= new EventHandler(this.OnActivated);
     if (this._attachDrag && Mouse.LeftButton == MouseButtonState.Pressed)
     {
         IntPtr           handle     = (new WindowInteropHelper(this)).Handle;
         Point            screenDPI  = this.PointToScreenDPI(Mouse.GetPosition(this));
         Win32Helper.RECT clientRect = Win32Helper.GetClientRect(handle);
         Win32Helper.RECT windowRect = Win32Helper.GetWindowRect(handle);
         base.Left        = screenDPI.X - (double)windowRect.Width / 2;
         base.Top         = screenDPI.Y - (double)(windowRect.Height - clientRect.Height) / 2;
         this._attachDrag = false;
         IntPtr intPtr = new IntPtr((int)screenDPI.X & 65535 | (int)screenDPI.Y << 16);
         Win32Helper.SendMessage(handle, 161, new IntPtr(2), intPtr);
     }
 }
        internal static void KeepInsideNearestMonitor(this ILayoutElementForFloatingWindow paneInsideFloatingWindow)
        {
            Win32Helper.RECT r = new Win32Helper.RECT
            {
                Left = (int)paneInsideFloatingWindow.FloatingLeft,
                Top  = (int)paneInsideFloatingWindow.FloatingTop
            };
            r.Bottom = r.Top + (int)paneInsideFloatingWindow.FloatingHeight;
            r.Right  = r.Left + (int)paneInsideFloatingWindow.FloatingWidth;

            const uint monitorDefaulttonearest = 0x00000002;
            const uint monitorDefaulttonull    = 0x00000000;

            System.IntPtr monitor = Win32Helper.MonitorFromRect(ref r, monitorDefaulttonull);
            if (monitor == System.IntPtr.Zero)
            {
                System.IntPtr nearestmonitor = Win32Helper.MonitorFromRect(ref r, monitorDefaulttonearest);
                if (nearestmonitor != System.IntPtr.Zero)
                {
                    Win32Helper.MonitorInfo monitorInfo = new Win32Helper.MonitorInfo();
                    monitorInfo.Size = Marshal.SizeOf(monitorInfo);
                    Win32Helper.GetMonitorInfo(nearestmonitor, monitorInfo);

                    if (paneInsideFloatingWindow.FloatingLeft < monitorInfo.Work.Left)
                    {
                        paneInsideFloatingWindow.FloatingLeft = monitorInfo.Work.Left + 10;
                    }

                    if (paneInsideFloatingWindow.FloatingLeft + paneInsideFloatingWindow.FloatingWidth > monitorInfo.Work.Right)
                    {
                        paneInsideFloatingWindow.FloatingLeft = monitorInfo.Work.Right - (paneInsideFloatingWindow.FloatingWidth + 10);
                    }

                    if (paneInsideFloatingWindow.FloatingTop < monitorInfo.Work.Top)
                    {
                        paneInsideFloatingWindow.FloatingTop = monitorInfo.Work.Top + 10;
                    }

                    if (paneInsideFloatingWindow.FloatingTop + paneInsideFloatingWindow.FloatingHeight > monitorInfo.Work.Bottom)
                    {
                        paneInsideFloatingWindow.FloatingTop = monitorInfo.Work.Bottom - (paneInsideFloatingWindow.FloatingHeight + 10);
                    }
                }
            }
        }
Exemplo n.º 4
0
        internal static void KeepInsideNearestMonitor(this ILayoutElementForFloatingWindow paneInsideFloatingWindow)
        {
            Win32Helper.RECT rECT = new Win32Helper.RECT()
            {
                Left   = (int)paneInsideFloatingWindow.FloatingLeft,
                Top    = (int)paneInsideFloatingWindow.FloatingTop,
                Bottom = rECT.Top + (int)paneInsideFloatingWindow.FloatingHeight,
                Right  = rECT.Left + (int)paneInsideFloatingWindow.FloatingWidth
            };
            uint num = 2;

            if (Win32Helper.MonitorFromRect(ref rECT, 0) == IntPtr.Zero)
            {
                IntPtr intPtr = Win32Helper.MonitorFromRect(ref rECT, num);
                if (intPtr != IntPtr.Zero)
                {
                    Win32Helper.MonitorInfo monitorInfo = new Win32Helper.MonitorInfo()
                    {
                        Size = Marshal.SizeOf(monitorInfo)
                    };
                    Win32Helper.GetMonitorInfo(intPtr, monitorInfo);
                    if (paneInsideFloatingWindow.FloatingLeft < (double)monitorInfo.Work.Left)
                    {
                        paneInsideFloatingWindow.FloatingLeft = (double)(monitorInfo.Work.Left + 10);
                    }
                    if (paneInsideFloatingWindow.FloatingLeft + paneInsideFloatingWindow.FloatingWidth > (double)monitorInfo.Work.Right)
                    {
                        paneInsideFloatingWindow.FloatingLeft = (double)monitorInfo.Work.Right - (paneInsideFloatingWindow.FloatingWidth + 10);
                    }
                    if (paneInsideFloatingWindow.FloatingTop < (double)monitorInfo.Work.Top)
                    {
                        paneInsideFloatingWindow.FloatingTop = (double)(monitorInfo.Work.Top + 10);
                    }
                    if (paneInsideFloatingWindow.FloatingTop + paneInsideFloatingWindow.FloatingHeight > (double)monitorInfo.Work.Bottom)
                    {
                        paneInsideFloatingWindow.FloatingTop = (double)monitorInfo.Work.Bottom - (paneInsideFloatingWindow.FloatingHeight + 10);
                    }
                }
            }
        }