Ejemplo n.º 1
0
        private void InitializeLocator(object sender, EventArgs e)
        {
            var settings = RestoreSettingsList();

            // get the object by this form's name
            _settings = settings.FirstOrDefault(f => f.Name == _form.Name);
            // if not found, set up the current form values to settings
            if (_settings == null)
            {
                _settings          = this;
                _settings.Name     = _form.Name;
                _settings.Size     = _form.Size;
                _settings.Location = _form.Location;
            }

            // restore settings to objects
            this.Name = _form.Name = _settings.Name;
            this.Size = _form.Size = _settings.Size;
            //this.Display = Screen.FromControl( _form ).DeviceName;

            if (SettingsAreNotOnScreen(_settings))
            {
                _settings.Location = new Point(200, 200);
            }
            this.Location = _form.Location = _settings.Location;
        }
Ejemplo n.º 2
0
        private bool SettingsAreNotOnScreen(FormLocator settings)
        {
            Screen screen = null;

            foreach (var s in Screen.AllScreens)
            {
                if (!FormIsOffScreen(s.WorkingArea, settings))
                {
                    screen = s;
                }
            }

            return(screen == null);
        }
Ejemplo n.º 3
0
        private bool FormIsOffScreen(Rectangle screenWorkingArea, FormLocator settings)
        {
            const int pixelBuffer           = 50;
            var       leftAllowablePixels   = screenWorkingArea.Left - settings.Size.Width + pixelBuffer;
            var       rightAllowablePixels  = screenWorkingArea.Right - pixelBuffer;
            var       topAllowablePixels    = screenWorkingArea.Top - (settings.Size.Height - pixelBuffer);
            var       bottomAllowablePixels = screenWorkingArea.Bottom - pixelBuffer;

            return
                (settings.Location.X < leftAllowablePixels
                 ||
                 settings.Location.X > rightAllowablePixels
                 ||
                 settings.Location.Y < topAllowablePixels
                 ||
                 settings.Location.Y > bottomAllowablePixels
                );
        }