private void _form_FormClosing(object sender, FormClosingEventArgs e) { if (_form != null) { var state = _form.WindowState == FormWindowState.Maximized ? FormWindowState.Maximized : FormWindowState.Normal; var height = Math.Max(_form.Size.Height, 100); var width = Math.Max(_form.Size.Width, 100); var top = Math.Max(0, Math.Min(_form.Top, Screen.FromControl(_form).Bounds.Height - 100)); var left = Math.Max(0, Math.Min(_form.Left, Screen.FromControl(_form).Bounds.Width - 100)); var props = new WindowSizeProps { State = (int)state, Top = top, Left = left, Width = width, Height = height }; var json = JsonConvert.SerializeObject(props, _settings); Properties.Settings.Default.WindowPositionSettings = json; Properties.Settings.Default.Save(); _form = null; } }
private void _form_FormClosing(object sender, FormClosingEventArgs e) { if (_form != null) { var state = _form.WindowState == FormWindowState.Maximized ? FormWindowState.Maximized : FormWindowState.Normal; var height = Math.Max(_form.Size.Height, 100); var width = Math.Max(_form.Size.Width, 100); var top = Math.Max(0, Math.Min(_form.Top, Screen.FromControl(_form).Bounds.Height - 100)); var left = Math.Max(0, Math.Min(_form.Left, Screen.FromControl(_form).Bounds.Width - 100)); var props = new WindowSizeProps { State = (int)state, Top = top, Left = left, Width = width, Height = height }; _settingsService.GetLocal().WindowPositionSettings = props; _form = null; } }