-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAboutBoxForm.cs
124 lines (114 loc) · 4.45 KB
/
AboutBoxForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System.Diagnostics;
using NLog;
namespace Numeric_List_Generator
{
/// <summary>
/// Represents the About Box form of the application.
/// </summary>
[DebuggerDisplay(value: $"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
internal partial class AboutBoxForm : Form
{
/// <summary>
/// Logger instance for logging messages and exceptions.
/// </summary>
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
/// <summary>
/// Returns a string that represents the current object for debugging purposes.
/// </summary>
/// <returns>A string that represents the current object.</returns>
private string GetDebuggerDisplay() => ToString();
/// <summary>
/// Sets a specific text to the status bar.
/// </summary>
/// <param name="text">The text with some information to display in the status bar.</param>
private void SetStatusbarText(string text)
{
labelInformation.Enabled = !string.IsNullOrWhiteSpace(value: text);
labelInformation.Text = text;
}
/// <summary>
/// Initializes a new instance of the <see cref="AboutBoxForm"/> class.
/// Sets the text of the labels to the corresponding assembly information.
/// </summary>
public AboutBoxForm()
{
InitializeComponent();
Logger.Info(message: "AboutBoxForm initialisiert.");
Text = $"Info über {AssemblyInfo.AssemblyTitle}";
labelProductName.Text = AssemblyInfo.AssemblyProduct;
labelVersion.Text = $"Version {AssemblyInfo.AssemblyVersion}";
labelCopyright.Text = AssemblyInfo.AssemblyCopyright;
linkLabelCompanyName.Text = AssemblyInfo.AssemblyCompany;
textBoxDescription.Text = AssemblyInfo.AssemblyDescription;
this.KeyDown += new KeyEventHandler(AboutBoxForm_KeyDown);
this.KeyPreview = true; // Ensures the form receives key events before the controls
}
/// <summary>
/// Handles the Load event of the AboutBoxForm control.
/// Initializes the status bar text to an empty string.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data.</param>
private void AboutBoxForm_Load(object sender, EventArgs e) => SetStatusbarText(text: string.Empty);
/// <summary>
/// Called when the mouse pointer moves over a control.
/// </summary>
/// <param name="sender">The event source.</param>
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data.</param>
private void SetStatusbar_Enter(object sender, EventArgs e)
{
if (sender is Control { AccessibleDescription: { } } control)
{
SetStatusbarText(text: control.AccessibleDescription);
}
else if (sender is ToolStripMenuItem { AccessibleDescription: { } } control2)
{
SetStatusbarText(text: control2.AccessibleDescription);
}
else if (sender is ToolStripStatusLabel { AccessibleDescription: { } } control3)
{
SetStatusbarText(text: control3.AccessibleDescription);
}
}
/// <summary>
/// Clears the information text of the status bar.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data.</param>
private void ClearStatusbar_Leave(object sender, EventArgs e) => SetStatusbarText(text: string.Empty);
private void LabelCompanyName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (linkLabelCompanyName.Tag != null)
{
string? url = linkLabelCompanyName.Tag.ToString();
if (!string.IsNullOrWhiteSpace(value: url))
{
try
{
using Process _ = Process.Start(fileName: url);
}
catch (Exception ex)
{
string message = $"Fehler beim Öffnen der URL: {ex.Message}.";
Debug.WriteLine(value: ex);
Logger.Error(exception: ex, message: message);
_ = MessageBox.Show(text: message, caption: "Fehler", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
}
}
}
}
/// <summary>
/// Handles the KeyDown event of the ExportDataSheetForm.
/// Closes the form when the Escape key is pressed.
/// </summary>
/// <param name="sender">The event source.</param>
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data.</param>
private void AboutBoxForm_KeyDown(object? sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
}
}