comparison 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
comparison
equal deleted inserted replaced
13:a36cc5c123f4 14:2db36ab759de
1 using System; 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing; 2 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms; 3 using System.Windows.Forms;
10 4
11 namespace ServerMonitorApp 5 namespace ServerMonitorApp
12 { 6 {
7 /// <summary>Form for showing help text in a floating popup.</summary>
13 public partial class QuickHelpForm : Form 8 public partial class QuickHelpForm : Form
14 { 9 {
15 private string Rtf; 10 private string Rtf;
16 11
17 public QuickHelpForm() 12 public QuickHelpForm()
18 { 13 {
19 InitializeComponent(); 14 InitializeComponent();
20 } 15 }
21 16
17 /// <summary>Creates a help popup form with the provided text.</summary>
18 /// <param name="rtf">Text to show in the popup in RTF format.</param>
22 public QuickHelpForm(string rtf) 19 public QuickHelpForm(string rtf)
23 { 20 {
24 InitializeComponent(); 21 InitializeComponent();
25 Rtf = rtf; 22 Rtf = rtf;
26 } 23 }
27 24
28 private void QuickHelpForm_Load(object sender, EventArgs e) 25 private void QuickHelpForm_Load(object sender, EventArgs e)
29 { 26 {
30 (Owner as CheckForm).HelpLocationChanged += Owner_HelpPositionChanged; 27 // Subscribe to the owner's notifications that the location of
31 HelpTextBox.ContentsResized += HelpTextBox_ContentsResized; // Causes form to resize after Rtf is assigned 28 // the Help button that triggered this popup has changed.
29 (Owner as CheckForm).HelpLocationChanged += Owner_HelpLocationChanged;
30 // Subscribe to this event before setting the text box's text
31 // so we can resize the form to match the text size.
32 HelpTextBox.ContentsResized += HelpTextBox_ContentsResized;
32 HelpTextBox.Rtf = Rtf; 33 HelpTextBox.Rtf = Rtf;
33 } 34 }
34 35
36 /// <summary>Resizes the popup form to fit the displayed text.</summary>
35 private void HelpTextBox_ContentsResized(object sender, ContentsResizedEventArgs e) 37 private void HelpTextBox_ContentsResized(object sender, ContentsResizedEventArgs e)
36 { 38 {
37 Height = e.NewRectangle.Height + 12; 39 Height = e.NewRectangle.Height + 12;
38 } 40 }
39 41
40 private void Owner_HelpPositionChanged(object sender, HelpLocationChangedEventArgs e) 42 /// <summary>Moves the popup form to always appear near the Help button that triggered it.</summary>
43 private void Owner_HelpLocationChanged(object sender, HelpLocationChangedEventArgs e)
41 { 44 {
42 Point location = e.HelpLocation; 45 Point location = e.HelpLocation;
43 location.Offset(24, 0); 46 location.Offset(24, 0);
44 Location = location; 47 Location = location;
45 } 48 }
46 49
50 // Hides the popup form when ESC is pressed.
47 private void Control_KeyDown(object sender, KeyEventArgs e) 51 private void Control_KeyDown(object sender, KeyEventArgs e)
48 { 52 {
49 if (e.KeyCode == Keys.Escape) 53 if (e.KeyCode == Keys.Escape)
50 Close(); 54 Close();
51 } 55 }
52 56
57 // Hides the popup form when it is clicked.
53 private void Control_Click(object sender, EventArgs e) 58 private void Control_Click(object sender, EventArgs e)
54 { 59 {
55 Close(); 60 Close();
56 } 61 }
57 } 62 }