1
1
using System . Diagnostics ;
2
+ using System . Media ;
2
3
using Julian_and_his_dates . Properties ;
3
4
using NLog ;
4
5
@@ -9,7 +10,7 @@ namespace Julian_and_his_dates
9
10
/// </summary>
10
11
[ DebuggerDisplay ( value : $ "{{{nameof(GetDebuggerDisplay)}(),nq}}") ]
11
12
12
- internal partial class AboutBoxForm : Form
13
+ internal sealed partial class AboutBoxForm : Form
13
14
{
14
15
/// <summary>
15
16
/// Logger instance for logging messages and exceptions.
@@ -19,12 +20,12 @@ internal partial class AboutBoxForm : Form
19
20
/// <summary>
20
21
/// The color used for white font.
21
22
/// </summary>
22
- private readonly Color colorWhiteFont = Color . WhiteSmoke ;
23
+ private readonly Color _colorWhiteFont = Color . WhiteSmoke ;
23
24
24
25
/// <summary>
25
26
/// The color used for the dark background.
26
27
/// </summary>
27
- private readonly Color colorDarkBackground = Color . FromArgb ( red : 29 , green : 32 , blue : 41 ) ;
28
+ private readonly Color _colorDarkBackground = Color . FromArgb ( red : 29 , green : 32 , blue : 41 ) ;
28
29
29
30
/// <summary>
30
31
/// Returns a string that represents the current object for debugging purposes.
@@ -36,7 +37,7 @@ internal partial class AboutBoxForm : Form
36
37
/// Sets a specific text to the status bar.
37
38
/// </summary>
38
39
/// <param name="text">The text with some information to display in the status bar.</param>
39
- private void SetStatusbarText ( string text )
40
+ private void SetStatusBarText ( string text )
40
41
{
41
42
labelInformation . Enabled = ! string . IsNullOrWhiteSpace ( value : text ) ;
42
43
labelInformation . Text = text ;
@@ -55,17 +56,17 @@ private static void HandleException(Exception ex, string message, object? sender
55
56
Debug . WriteLine ( value : msg ) ;
56
57
Console . WriteLine ( value : msg ) ;
57
58
Logger . Error ( exception : ex , message : msg ) ;
58
- _ = MessageBox . Show ( text : message , caption : "Error" , buttons : MessageBoxButtons . OK , icon : MessageBoxIcon . Error ) ;
59
+ _ = MessageBox . Show ( text : message , caption : @ "Error", buttons : MessageBoxButtons . OK , icon : MessageBoxIcon . Error ) ;
59
60
}
60
61
61
62
/// <summary>
62
63
/// Sets the dark mode
63
64
/// </summary>
64
65
public void SetDarkMode ( )
65
66
{
66
- statusStrip . BackColor = colorDarkBackground ;
67
- labelInformation . BackColor = colorDarkBackground ;
68
- labelInformation . ForeColor = colorWhiteFont ;
67
+ statusStrip . BackColor = _colorDarkBackground ;
68
+ labelInformation . BackColor = _colorDarkBackground ;
69
+ labelInformation . ForeColor = _colorWhiteFont ;
69
70
}
70
71
71
72
/// <summary>
@@ -76,14 +77,14 @@ public AboutBoxForm()
76
77
{
77
78
InitializeComponent ( ) ;
78
79
Logger . Info ( message : "AboutBoxForm initialized." ) ;
79
- Text = $ "Info about { AssemblyInfo . AssemblyTitle } ";
80
+ Text = $@ "Info about { AssemblyInfo . AssemblyTitle } ";
80
81
labelProductName . Text = AssemblyInfo . AssemblyProduct ;
81
- labelVersion . Text = $ "Version { AssemblyInfo . AssemblyVersion } ";
82
+ labelVersion . Text = $@ "Version { AssemblyInfo . AssemblyVersion } ";
82
83
labelCopyright . Text = AssemblyInfo . AssemblyCopyright ;
83
84
labelCompanyName . Text = AssemblyInfo . AssemblyCompany ;
84
85
textBoxDescription . Text = AssemblyInfo . AssemblyDescription ;
85
- this . KeyDown += new KeyEventHandler ( AboutBoxForm_KeyDown ) ;
86
- this . KeyPreview = true ; // Ensures the form receives key events before the controls
86
+ KeyDown += AboutBoxForm_KeyDown ;
87
+ KeyPreview = true ; // Ensures the form receives key events before the controls
87
88
}
88
89
89
90
/// <summary>
@@ -93,7 +94,7 @@ public AboutBoxForm()
93
94
/// <param name="e"></param>
94
95
private void LogoPictureBox_Click ( object sender , EventArgs e )
95
96
{
96
- using System . Media . SoundPlayer sound = new ( stream : Resources . wavBleep ) ;
97
+ using SoundPlayer sound = new ( stream : Resources . wavBleep ) ;
97
98
sound . Play ( ) ;
98
99
}
99
100
@@ -103,45 +104,26 @@ private void LogoPictureBox_Click(object sender, EventArgs e)
103
104
/// </summary>
104
105
/// <param name="sender">The source of the event.</param>
105
106
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data.</param>
106
- private void AboutBoxForm_Load ( object sender , EventArgs e ) => SetStatusbarText ( text : string . Empty ) ;
107
+ private void AboutBoxForm_Load ( object sender , EventArgs e ) => SetStatusBarText ( text : string . Empty ) ;
107
108
108
109
/// <summary>
109
110
/// Detect the accessibility description to set as information text in the status bar
110
111
/// </summary>
111
112
/// <param name="sender">The event source</param>
112
113
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data</param>
113
- private void SetStatusbar_Enter ( object sender , EventArgs e )
114
+ private void SetStatusBar_Enter ( object sender , EventArgs e )
114
115
{
115
- try
116
+ // Set the status bar text based on the sender's accessible description
117
+ switch ( sender )
116
118
{
117
- if ( sender is Control { AccessibleDescription : { } } control )
118
- {
119
- SetStatusbarText ( text : control . AccessibleDescription ) ;
120
- }
121
- else if ( sender is ToolStripMenuItem { AccessibleDescription : { } } control2 )
122
- {
123
- SetStatusbarText ( text : control2 . AccessibleDescription ) ;
124
- }
125
- else if ( sender is ToolStripStatusLabel { AccessibleDescription : { } } control3 )
126
- {
127
- SetStatusbarText ( text : control3 . AccessibleDescription ) ;
128
- }
129
- else if ( sender is ToolStripButton { AccessibleDescription : { } } control4 )
130
- {
131
- SetStatusbarText ( text : control4 . AccessibleDescription ) ;
132
- }
133
- else if ( sender is ToolStripDropDownButton { AccessibleDescription : { } } control5 )
134
- {
135
- SetStatusbarText ( text : control5 . AccessibleDescription ) ;
136
- }
137
- else if ( sender is ToolStripSplitButton { AccessibleDescription : { } } control6 )
138
- {
139
- SetStatusbarText ( text : control6 . AccessibleDescription ) ;
140
- }
141
- }
142
- catch ( Exception ex )
143
- {
144
- HandleException ( ex : ex , message : "An error occurred while setting the status bar text." , sender : sender , e : e ) ;
119
+ // If the sender is a control with an accessible description, set the status bar text
120
+ // If the sender is a ToolStripItem with an accessible description, set the status bar text
121
+ case Control { AccessibleDescription : not null } control :
122
+ SetStatusBarText ( text : control . AccessibleDescription ) ;
123
+ break ;
124
+ case ToolStripItem { AccessibleDescription : not null } item :
125
+ SetStatusBarText ( text : item . AccessibleDescription ) ;
126
+ break ;
145
127
}
146
128
}
147
129
@@ -150,7 +132,7 @@ private void SetStatusbar_Enter(object sender, EventArgs e)
150
132
/// </summary>
151
133
/// <param name="sender">The source of the event.</param>
152
134
/// <param name="e">The <see cref="EventArgs"/> instance that contains the event data.</param>
153
- private void ClearStatusbar_Leave ( object sender , EventArgs e ) => SetStatusbarText ( text : string . Empty ) ;
135
+ private void ClearStatusBar_Leave ( object sender , EventArgs e ) => SetStatusBarText ( text : string . Empty ) ;
154
136
155
137
/// <summary>
156
138
/// Handles the KeyDown event of the ExportDataSheetForm.
@@ -162,7 +144,7 @@ private void AboutBoxForm_KeyDown(object? sender, KeyEventArgs e)
162
144
{
163
145
if ( e . KeyCode == Keys . Escape )
164
146
{
165
- this . Close ( ) ;
147
+ Close ( ) ;
166
148
}
167
149
}
168
150
}
0 commit comments