Пример #1
0
        private double GetWindowsTop()
        {
            var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);

            if (UserSettingStorage.Instance.RememberLastLaunchLocation)
            {
                var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
                var coordY     = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight);
                UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top;
            }
            else
            {
                UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - tbQuery.ActualHeight) / 4 + screen.WorkingArea.Top;
            }
            return(UserSettingStorage.Instance.WindowTop);
        }
Пример #2
0
        private double GetWindowsLeft()
        {
            var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);

            if (UserSettingStorage.Instance.RememberLastLaunchLocation)
            {
                var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
                var coordX     = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
                UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left;
            }
            else
            {
                UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) / 2 + screen.WorkingArea.Left;
            }

            return(UserSettingStorage.Instance.WindowLeft);
        }
Пример #3
0
        private void SettingCollection_Initialized(object sender, System.EventArgs e)
        {
            SettingCollection subject = (SettingCollection)sender;
            Window            window  = (Window)subject.Owner;

            // Restore the original window position and size in case the window is outside the desktop working area.
            int    left   = (int)window.Left;
            int    top    = (int)window.Top;
            int    width  = (int)window.ActualWidth;
            int    height = (int)window.ActualHeight;
            Screen screen = Screen.FromRectangle(new Rectangle(left, top, width, height));

            if (screen == null ||
                !(screen.WorkingArea.Contains(new DPoint(left + TOLERANCE_X, top + TOLERANCE_Y)) ||
                  screen.WorkingArea.Contains(new DPoint(left + width - TOLERANCE_X, top + TOLERANCE_Y))))
            {
                window.Left   = this.positionAndSizeBackup[0];
                window.Top    = this.positionAndSizeBackup[1];
                window.Width  = this.positionAndSizeBackup[2];
                window.Height = this.positionAndSizeBackup[3];
            }

            this.positionAndSizeBackup = null;
        }