Mercurial > servermonitor
diff ServerMonitor/Forms/SettingsForm.cs @ 16:7626b099aefd
More comments.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Tue, 30 Apr 2019 20:40:58 -0400 |
parents | 75ca86e0862c |
children | f6235dc0a8ec |
line wrap: on
line diff
--- a/ServerMonitor/Forms/SettingsForm.cs Mon Apr 22 21:11:27 2019 -0400 +++ b/ServerMonitor/Forms/SettingsForm.cs Tue Apr 30 20:40:58 2019 -0400 @@ -1,18 +1,12 @@ using Microsoft.Win32; using ServerMonitorApp.Properties; using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; using System.Windows.Forms; namespace ServerMonitorApp { + /// <summary>Application settings form.</summary> public partial class SettingsForm : Form { private readonly string autorunKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; @@ -26,11 +20,13 @@ private void SettingsForm_Load(object sender, EventArgs e) { Icon = Resources.icon; + // Populate each action combo box with the available actions to perform on failure. foreach (ComboBox comboBox in new object[] { ErrorComboBox, WarningComboBox, InformationComboBox }) { comboBox.DataSource = Enum.GetValues(typeof(FailAction)); comboBox.Format += FailActionComboBox_Format; } + // Initialize controls with current settings. AutorunCheckBox.Checked = GetAutorun(); KeepRunningCheckBox.Checked = Settings.Default.HideToNotificationArea; KeepLogDaysInput.Value = Settings.Default.KeepLogDays; @@ -39,6 +35,8 @@ InformationComboBox.SelectedItem = Settings.Default.InformationAction; } + /// <summary>Gets whether an autorun registry key for this program exists.</summary> + /// <returns>Whether an autorun registry key for this program exists</returns> private bool GetAutorun() { RegistryKey key = Registry.CurrentUser.OpenSubKey(autorunKey, false); @@ -46,6 +44,8 @@ return value.StartsWith(Application.ExecutablePath); } + /// <summary>Sets whether this program should automatically start with Windows.</summary> + /// <param name="autorun">Whether autorun should be enabled or disabled.</param> private void SetAutorun(bool autorun) { RegistryKey key = Registry.CurrentUser.OpenSubKey(autorunKey, true); @@ -55,11 +55,15 @@ key.DeleteValue(autorunName, false); } + /// <summary>Shows a human readable description of possible check failure actions in the combo box.</summary> private void FailActionComboBox_Format(object sender, ListControlConvertEventArgs e) { + // Transform the "CamelCase" enum name in to a "Camel case" name, adding + // spaces and making all characters besides the first lower case. e.Value = e.Value.ToString().Substring(0, 1) + Regex.Replace(e.Value.ToString(), "(\\B[A-Z])", " $1").ToLower().Substring(1); } + /// <summary>Saves the user settings and closes the form.</summary> private void OkButton_Click(object sender, EventArgs e) { Settings.Default.HideToNotificationArea = KeepRunningCheckBox.Checked; @@ -72,6 +76,7 @@ Close(); } + /// <summary>Closes the form without saving settings.</summary> private void CancelSettingsButton_Click(object sender, EventArgs e) { Close();