ClientSettingsProvider.SettingsSaved 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在设置提供程序尝试将属性值保存到 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。