共用方式為


ClientSettingsProvider.SettingsSaved 事件

定義

在設定提供者嘗試將屬性值儲存至 Web 設定服務之後發生。

public:
 event EventHandler<System::Web::ClientServices::Providers::SettingsSavedEventArgs ^> ^ SettingsSaved;
public event EventHandler<System.Web.ClientServices.Providers.SettingsSavedEventArgs> SettingsSaved;
member this.SettingsSaved : EventHandler<System.Web.ClientServices.Providers.SettingsSavedEventArgs> 
Public Custom Event SettingsSaved As EventHandler(Of SettingsSavedEventArgs) 
Public Event SettingsSaved As EventHandler(Of SettingsSavedEventArgs) 

事件類型

範例

下列範例程式代碼示範如何使用這個事件來顯示未成功儲存的設定清單。

private void AttachSettingsSavedEventHandler()
{
    ((ClientSettingsProvider)Properties.Settings.Default.Providers
        ["System.Web.ClientServices.Providers.ClientSettingsProvider"])
        .SettingsSaved +=
        new EventHandler<SettingsSavedEventArgs>(Form1_SettingsSaved);
}

private void Form1_SettingsSaved(object sender,
    SettingsSavedEventArgs e)
{
    // If any settings were not saved, display a list of them.
    if (e.FailedSettingsList.Count > 0)
    {
        String failedSettings = String.Join(
            Environment.NewLine,
            e.FailedSettingsList.ToArray());

        String message = String.Format("{0}{1}{1}{2}",
            "The following setting(s) were not saved:",
            Environment.NewLine, failedSettings);

        MessageBox.Show(message, "Unable to save settings",
            MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}
Private WithEvents settingsProvider As ClientSettingsProvider = My.Settings _
    .Providers("System.Web.ClientServices.Providers.ClientSettingsProvider")

Private Sub Form1_SettingsSaved(ByVal sender As Object, _
    ByVal e As SettingsSavedEventArgs) _
    Handles settingsProvider.SettingsSaved

    ' If any settings were not saved, display a list of them.
    If e.FailedSettingsList.Count > 0 Then

        Dim failedSettings As String = String.Join( _
            Environment.NewLine, e.FailedSettingsList.ToArray())

        Dim message As String = String.Format("{0}{1}{1}{2}", _
            "The following setting(s) were not saved:", _
            Environment.NewLine, failedSettings)

        MessageBox.Show(message, "Unable to save settings", _
            MessageBoxButtons.OK, MessageBoxIcon.Warning)

    End If

End Sub

備註

此事件會在設定提供者存取設定服務之後發生,即使設定未成功儲存也一樣。 提供者可能無法儲存設定的其中一個原因是目前使用者已註銷。您可以使用 SettingsSavedEventArgs.FailedSettingsList 屬性來判斷是否未成功儲存任何設定。

如果設定提供者無法存取設定服務,這會導致提供者擲回 WebException,則不會發生此事件。

適用於

另請參閱