using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Configuration; using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Windows.Forms; namespace ApplicationSettingsSample { partial class MainForm : Form { //MySettings settings = new MySettings(); ApplicationSettingsSample.Properties.Settings settings = new ApplicationSettingsSample.Properties.Settings(); public MainForm() { InitializeComponent(); Properties.Settings.Default.SettingsLoaded += Default_SettingsLoaded; Properties.Settings.Default.SettingsSaving += Default_SettingsSaving; } void Default_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e) { MessageBox.Show("Settings loaded by " + e.Provider.Name); } void getSettingsButton_Click(object sender, EventArgs e) { // Both settings are loaded when the first line executes // since they both use the default LocalFileSettingsProvider //int highScore = settings.HighScore; //string assemblyPaths = settings.AssemblyPaths; // No settings are loaded int highScore = Properties.Settings.Default.HighScore; // All settings are loaded string assemblyPaths = Properties.Settings.Default.AssemblyPaths; } private void readSettingsValuesButton_Click(object sender, EventArgs e) { (new ReadSettingsValuesForm()).ShowDialog(); } private void readSettingsButton_Click(object sender, EventArgs e) { (new ReadSettingsForm()).ShowDialog(); } private void updateSettingButton_Click(object sender, EventArgs e) { (new UpdateSettingForm()).ShowDialog(); } private void configurationManagerButton_Click(object sender, EventArgs e) { (new ConfigurationManagerForm()).ShowDialog(); } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { Properties.Settings.Default.Save(); } void Default_SettingsSaving(object sender, CancelEventArgs e) { // Ask if user really wants to save changed settings DialogResult result = MessageBox.Show("Save Settings before application shutdown?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question); e.Cancel = (result == DialogResult.No); } } }