コード例 #1
0
 private void OpenUserSettings()
 {
     if (File.Exists(Settings.DefaultDirectory + "\\settings.xml"))
     {
         try
         {
             using (var reader = new StreamReader(Settings.DefaultDirectory + "\\settings.xml"))
             {
                 currentUserSettings = XmlUserSettings.Read(reader);
             }
             showScreenNamesToolStripMenuItem.Checked      = currentUserSettings.ShowScreenNames;
             showZoneNamesToolStripMenuItem.Checked        = currentUserSettings.ShowZoneNames;
             runWhenWindowsStartsToolStripMenuItem.Checked = currentUserSettings.StartWithWindows;
             openProfileName = currentUserSettings.LastOpenFile;
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error reading user settings: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         if (currentUserSettings == null)
         {
             currentUserSettings = new UserSettings();
         }
     }
     else
     {
         currentUserSettings = new UserSettings();
     }
 }
コード例 #2
0
        private void SaveUserSettings()
        {
            if (currentUserSettings == null)
            {
                currentUserSettings = new UserSettings();
            }
            currentUserSettings.ShowScreenNames  = showScreenNamesToolStripMenuItem.Checked;
            currentUserSettings.ShowZoneNames    = showZoneNamesToolStripMenuItem.Checked;
            currentUserSettings.StartWithWindows = runWhenWindowsStartsToolStripMenuItem.Checked;
            currentUserSettings.LastOpenFile     = openProfileName;

            try
            {
                using (var writer = new StreamWriter(Settings.DefaultDirectory + "\\settings.xml"))
                {
                    XmlUserSettings.Save(writer, currentUserSettings);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error saving user settings: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }