using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; namespace ApplicationSettingsSample { partial class UpdateSettingForm : Form { public UpdateSettingForm() { InitializeComponent(); } private void UpdateSettingForm_Load(object sender, EventArgs e) { // Handle SettingChanging event Properties.Settings.Default.SettingChanging += Default_SettingChanging; // Handle PropertyChanged event Properties.Settings.Default.PropertyChanged += Default_PropertyChanged; // Get setting value this.settingTextBox.Text = Properties.Settings.Default.HighScore.ToString(); } private void updateSettingButton_Click(object sender, EventArgs e) { // Attempt to set value // Note: when this line is called, the SettingChanging // event is fired Properties.Settings.Default.HighScore = int.Parse(this.settingTextBox.Text); } void Default_SettingChanging(object sender, SettingChangingEventArgs e) { // Validate HighScore if( e.SettingName == "HighScore" ) { if( ((int)e.NewValue) < 0 ) { MessageBox.Show("HighScore can't be less than 0."); e.Cancel = true; } } } void Default_PropertyChanged(object sender, PropertyChangedEventArgs e) { MessageBox.Show("Woohoo! " + e.PropertyName + " was changed."); } } }