diff ServerMonitor/Forms/QuickHelpForm.cs @ 14:2db36ab759de

Add comments.
author Brad Greco <brad@bgreco.net>
date Mon, 22 Apr 2019 21:10:42 -0400
parents 3e1a2131f897
children
line wrap: on
line diff
--- a/ServerMonitor/Forms/QuickHelpForm.cs	Mon Apr 15 19:25:27 2019 -0400
+++ b/ServerMonitor/Forms/QuickHelpForm.cs	Mon Apr 22 21:10:42 2019 -0400
@@ -1,15 +1,10 @@
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
 using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace ServerMonitorApp
 {
+    /// <summary>Form for showing help text in a floating popup.</summary>
     public partial class QuickHelpForm : Form
     {
         private string Rtf;
@@ -19,6 +14,8 @@
             InitializeComponent();
         }
 
+        /// <summary>Creates a help popup form with the provided text.</summary>
+        /// <param name="rtf">Text to show in the popup in RTF format.</param>
         public QuickHelpForm(string rtf)
         {
             InitializeComponent();
@@ -27,29 +24,37 @@
 
         private void QuickHelpForm_Load(object sender, EventArgs e)
         {
-            (Owner as CheckForm).HelpLocationChanged += Owner_HelpPositionChanged;
-            HelpTextBox.ContentsResized += HelpTextBox_ContentsResized; // Causes form to resize after Rtf is assigned
+            // Subscribe to the owner's notifications that the location of
+            // the Help button that triggered this popup has changed.
+            (Owner as CheckForm).HelpLocationChanged += Owner_HelpLocationChanged;
+            // Subscribe to this event before setting the text box's text
+            // so we can resize the form to match the text size.
+            HelpTextBox.ContentsResized += HelpTextBox_ContentsResized;
             HelpTextBox.Rtf = Rtf;
         }
 
+        /// <summary>Resizes the popup form to fit the displayed text.</summary>
         private void HelpTextBox_ContentsResized(object sender, ContentsResizedEventArgs e)
         {
             Height = e.NewRectangle.Height + 12;
         }
 
-        private void Owner_HelpPositionChanged(object sender, HelpLocationChangedEventArgs e)
+        /// <summary>Moves the popup form to always appear near the Help button that triggered it.</summary>
+        private void Owner_HelpLocationChanged(object sender, HelpLocationChangedEventArgs e)
         {
             Point location = e.HelpLocation;
             location.Offset(24, 0);
             Location = location;
         }
 
+        // Hides the popup form when ESC is pressed.
         private void Control_KeyDown(object sender, KeyEventArgs e)
         {
             if (e.KeyCode == Keys.Escape)
                 Close();
         }
 
+        // Hides the popup form when it is clicked.
         private void Control_Click(object sender, EventArgs e)
         {
             Close();