private void LoadSettings() { if (!File.Exists(settingsFile)) { CreateDefaultSettings(); return; } using (StreamReader stream = new StreamReader(settingsFile)) { XmlSerializer serialiser = new XmlSerializer(typeof(Settings)); try { settings = (Settings)serialiser.Deserialize(stream); } catch (InvalidOperationException) { CreateDefaultSettings(); return; } } this.Location = settings.position; }
private void CreateDefaultSettings() { settings = new Settings(); int xPos = Screen.PrimaryScreen.Bounds.Width - 285; int yPos = Screen.PrimaryScreen.WorkingArea.Height - 262; this.Left = xPos; this.Top = yPos; settings.position = new Point(xPos, yPos); using (StreamWriter stream = new StreamWriter(settingsFile)) { XmlSerializer serializer = new XmlSerializer(typeof(Settings)); serializer.Serialize(stream, settings); } }