SettingsSavedEventArgs 类

定义

SettingsSaved 事件提供数据。

public ref class SettingsSavedEventArgs : EventArgs
public class SettingsSavedEventArgs : EventArgs
type SettingsSavedEventArgs = class
    inherit EventArgs
Public Class SettingsSavedEventArgs
Inherits EventArgs
继承
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

注解

ClientSettingsProvider.SettingsSaved 事件在设置提供程序访问设置服务后发生,即使设置未成功保存也是如此。 提供程序可能无法保存设置的一个原因是当前用户是否已注销。可以使用 FailedSettingsList 属性来确定是否未成功保存任何设置。

如果设置提供程序无法访问设置服务,导致提供程序引发 WebException,则不会发生此事件。

有关如何处理事件的详细信息,请参阅 处理和引发事件

构造函数

SettingsSavedEventArgs(IEnumerable<String>)

初始化 SettingsSavedEventArgs 类的新实例。

属性

FailedSettingsList

获取 ClientSettingsProvider 未能保存到服务器上的设置。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅