/// <summary> /// Resizes the form based on the current form state object /// </summary> public void RestoreForm() { // abort if no form if (_form == null) { return; } if (_formState == null) { return; } // save current visible state and hide _isBeingResized = true; var oldVisible = _form.Visible; if (_formShown) { _form.Visible = false; } try { // if outside of desktop bounds, set to 100, 100 if (!DesktopHelper.IsLocationInDesktop(_formState.Location)) { _formState.Location = new Point(100, 100); } // if minimized, set to normal if (_formState.WindowState == FormWindowState.Minimized) { _formState.WindowState = FormWindowState.Normal; } // set form state to normal for resizing if (_form.WindowState != FormWindowState.Normal) { _form.WindowState = FormWindowState.Normal; } // set size and location _form.Size = _formState.Size; _form.Location = _formState.Location; } catch { } // restore visibility _isBeingResized = false; if (_formShown) { _form.Visible = oldVisible; } }