public void SaveSettings() { try { // Create an instance of the Settings class Settings settings = new Settings(); settings.AllowedShapes = this.allowedShapes; settings.DrawSpeed = this.drawSpeed; if (settings.DrawSpeed == Settings.Speed.Custom) settings.CustomSpeed = this.customSpeed; else settings.CustomSpeed = 0; settings.UseTransparency = this.useTransparency; // Create an instance of System.Xml.Serialization.XmlSerializer XmlSerializer serializer = new XmlSerializer(settings.GetType()); // Create an instance of System.IO.TextWriter // to save the serialized object to disk TextWriter textWriter = new StreamWriter(this.settingsPath); // Serialize the settings object serializer.Serialize(textWriter, settings); // Close the TextWriter textWriter.Close(); } catch (Exception ex) { MessageBox.Show(string.Format("Error saving serialized settings! {0}", ex.Message), "Dave on C# Screen Saver", MessageBoxButtons.OK, MessageBoxIcon.Error); } }