Пример #1
0
        /// <summary>
        /// Saves the form state.
        /// </summary>
        /// <remarks>
        /// All exceptions are ignored to make sure that this miscellaneous function
        /// does never break the application.
        /// </remarks>
        /// <returns>True if form state was successfully stored, false if an error
        /// occurred</returns>
        public bool SaveState()
        {
            if (Form.WindowState == FormWindowState.Minimized)
            {
                // don't save state if minimized
                return(false);
            }

            try
            {
                // get the current form state
                T formState = GetCurrentState();

                // write form state
                FormStatePersistence.WriteToXml(_fileName, formState, typeof(T));
            }
            catch (Exception ex)
            {
                _msg.Warn("Error saving form state", ex);

                // ignore errors
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Saves the window settings for the form.
        /// </summary>
        /// <remarks>
        /// All exceptions are ignored to make sure that this miscellaneous function
        /// does never break the application.
        /// </remarks>
        /// <returns>True if settings were successfully stored, false if an error
        /// occurred</returns>
        public bool SaveSettings()
        {
            if (_form.WindowState == FormWindowState.Minimized)
            {
                // don't save state if minimized
                return(false);
            }
            else
            {
                try
                {
                    // get the current settings for the form
                    WindowSettings settings = GetCurrentSettings();

                    // write settings
                    FormStatePersistence.WriteToXml(_fileName, settings, _settingsType);
                }
                catch (Exception ex)
                {
                    _msg.Warn("Error saving window settings", ex);

                    // ignore errors
                    return(false);
                }

                return(true);
            }
        }