ApplicationSettingsBase.SettingsSaving Event

Definition

Occurs before values are saved to the data store.

C#
public event System.Configuration.SettingsSavingEventHandler SettingsSaving;

Event Type

Examples

The following code example shows the SettingsSaving event handler for object of type FormSettings, which is a wrapper class derived from ApplicationSettingsBase. The handler queries the user to save the current application settings property values. The full code example is listed in the ApplicationSettingsBase class overview.

C#
void frmSettings1_SettingsSaving(object sender, CancelEventArgs e)
{
    //Should check for settings changes first.
    DialogResult dr = MessageBox.Show(
                    "Save current values for application settings?",
                    "Save Settings", MessageBoxButtons.YesNo);
    if (DialogResult.No == dr)
    {
        e.Cancel = true;
    }
}

Remarks

The SettingsSaving event is raised by the Save method before it stores the application settings properties to their associated data store. The associated event handler can cancel this event.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also