-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericListGeneratorForm.cs
384 lines (336 loc) · 14.4 KB
/
NumericListGeneratorForm.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
using System.Diagnostics;
using System.Windows.Forms.VisualStyles;
namespace Numeric_List_Generator
{
/// <summary>
/// Main Form
/// </summary>
[DebuggerDisplay(value: $"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
public partial class NumericListGeneratorForm : Form
{
/// <summary>
/// timeSpan
/// </summary>
private TimeSpan timeSpan;
/// <summary>
/// backupListUndo, backupListRedo
/// </summary>
private string backupListUndo, backupListRedo;
/// <summary>
/// startTime, endTime
/// </summary>
private DateTime startTime, endTime;
#region
/// <summary>
/// Constructor
/// </summary>
public NumericListGeneratorForm() => InitializeComponent();
#endregion
#region
/// <summary>
/// Get Debugger Display
/// </summary>
/// <returns>Return the debugger display</returns>
private string GetDebuggerDisplay() => ToString();
/// <summary>
/// Set a specific text to the status bar
/// </summary>
/// <param name="text">text with some information</param>
private void SetStatusbarText(string text)
{
toolStripStatusLabelInformation.Enabled = !string.IsNullOrEmpty(value: text);
toolStripStatusLabelInformation.Text = text;
}
private void UpdateStatusBarStatistic()
{
if (toolStripStatusLabelSize.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelSize.Text = $"Größe: {textBoxList.Text.Length} Bytes";
}
if (toolStripStatusLabelLines.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelLines.Text = $"Zeilen: {textBoxList.Lines.LongLength}";
}
if (toolStripStatusLabelTimeSpan.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelTimeSpan.Text = $"Dauer: {timeSpan:hh\\:mm\\:ss\\.ff}";
}
if (toolStripStatusLabelLim.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelLim.Text = $"LIM: {(int)numericUpDownNumberMaximum.Value / timeSpan.TotalSeconds:N4} ips";
}
}
private void DisableControls()
{
toolStripMenuItemList.Enabled = false;
textBoxStringBeforeNumber.Enabled = false;
numericUpDownNumberMinimum.Enabled = false;
numericUpDownNumberMaximum.Enabled = false;
checkBoxFillWithZeros.Enabled = false;
textBoxStringAfterNumber.Enabled = false;
buttonCreateList.Enabled = false;
buttonAddToList.Enabled = false;
buttonDeleteList.Enabled = false;
buttonCopyList.Enabled = false;
buttonSaveList.Enabled = false;
buttonUndo.Enabled = false;
buttonRedo.Enabled = false;
toolStripMenuItemListUndo.Enabled = false;
toolStripMenuItemListRedo.Enabled = false;
textBoxList.Enabled = false;
}
private void EnableControls()
{
toolStripMenuItemList.Enabled = true;
textBoxStringBeforeNumber.Enabled = true;
numericUpDownNumberMinimum.Enabled = true;
numericUpDownNumberMaximum.Enabled = true;
checkBoxFillWithZeros.Enabled = true;
textBoxStringAfterNumber.Enabled = true;
buttonCreateList.Enabled = true;
buttonAddToList.Enabled = true;
buttonDeleteList.Enabled = true;
buttonCopyList.Enabled = true;
buttonSaveList.Enabled = true;
buttonUndo.Enabled = true;
toolStripMenuItemListUndo.Enabled = true;
textBoxList.Enabled = true;
}
private void CheckStayOnTop() => TopMost = toolStripMenuItemSettingsStayOnTop.Checked;
#endregion
private void NumericListGeneratorForm_Load(object sender, EventArgs e)
{
SetStatusbarText(text: string.Empty);
buttonUndo.Enabled = false;
buttonRedo.Enabled = false;
toolStripMenuItemListUndo.Enabled = false;
toolStripMenuItemListRedo.Enabled = false;
UpdateStatusBarStatistic();
}
#region Enter event handlers
/// <summary>
/// Detect the accessibility description to set as information text in the status bar
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
private void SetStatusbar_Enter(object sender, EventArgs e)
{
switch (sender)
{
case TextBox textBox: SetStatusbarText(text: textBox.AccessibleDescription); break;
case Button button: SetStatusbarText(text: button.AccessibleDescription); break;
case RadioButton radioButton: SetStatusbarText(text: radioButton.AccessibleDescription); break;
case CheckBox checkBox: SetStatusbarText(text: checkBox.AccessibleDescription); break;
case DateTimePicker dateTimePicker: SetStatusbarText(text: dateTimePicker.AccessibleDescription); break;
case Label label: SetStatusbarText(text: label.AccessibleDescription); break;
case PictureBox pictureBox: SetStatusbarText(text: pictureBox.AccessibleDescription); break;
case CheckedListBox checkedListBox: SetStatusbarText(text: checkedListBox.AccessibleDescription); break;
case ComboBox box: SetStatusbarText(text: box.AccessibleDescription); break;
case DataGridView view: SetStatusbarText(text: view.AccessibleDescription); break;
case GroupBox group: SetStatusbarText(text: group.AccessibleDescription); break;
case ListBox box: SetStatusbarText(text: box.AccessibleDescription); break;
case ListView view: SetStatusbarText(text: view.AccessibleDescription); break;
case MaskedTextBox box: SetStatusbarText(text: box.AccessibleDescription); break;
case NumericUpDown numericUpDown: SetStatusbarText(text: numericUpDown.AccessibleDescription); break;
case MonthCalendar monthCalendar: SetStatusbarText(text: monthCalendar.AccessibleDescription); break;
case PropertyGrid propertyGrid: SetStatusbarText(text: propertyGrid.AccessibleDescription); break;
case RichTextBox richTextBox: SetStatusbarText(text: richTextBox.AccessibleDescription); break;
case ScrollBar scrollBar: SetStatusbarText(text: scrollBar.AccessibleDescription); break;
case TrackBar trackBar: SetStatusbarText(text: trackBar.AccessibleDescription); break;
case WebBrowser webBrowser: SetStatusbarText(text: webBrowser.AccessibleDescription); break;
case DomainUpDown domainUpDown: SetStatusbarText(text: domainUpDown.AccessibleDescription); break;
case ToolStripButton toolStripButton: SetStatusbarText(text: toolStripButton.AccessibleDescription); break;
case ToolStripMenuItem toolStripMenuItem: SetStatusbarText(text: toolStripMenuItem.AccessibleDescription); break;
case ToolStripLabel toolStripLabel: SetStatusbarText(text: toolStripLabel.AccessibleDescription); break;
case ToolStripComboBox toolStripComboBox: SetStatusbarText(text: toolStripComboBox.AccessibleDescription); break;
case ToolStripDropDown toolStripDropDown: SetStatusbarText(text: toolStripDropDown.AccessibleDescription); break;
case ToolStripDropDownButton toolStripDropDownButton: SetStatusbarText(text: toolStripDropDownButton.AccessibleDescription); break;
case ToolStripDropDownItem toolStripDropDownItem: SetStatusbarText(text: toolStripDropDownItem.AccessibleDescription); break;
case ToolStripProgressBar progressBar: SetStatusbarText(text: progressBar.AccessibleDescription); break;
case ToolStripSeparator toolStripSeparator: SetStatusbarText(text: toolStripSeparator.AccessibleDescription); break;
case ToolStripTextBox toolStripTextBox: SetStatusbarText(text: toolStripTextBox.AccessibleDescription); break;
}
}
#endregion
#region Leave event handlers
/// <summary>
/// Clear the information text of the status bar
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="e"/> and <paramref name="sender"/> are not needed, but must be indicated.</remarks>
private void ClearStatusbar_Leave(object sender, EventArgs e) => SetStatusbarText(text: string.Empty);
#endregion
private void ButtonAddToList_Click(object sender, EventArgs e)
{
DisableControls();
backupListUndo = textBoxList.Text;
startTime = DateTime.Now;
progressBar.Minimum = 0;
progressBar.Maximum = (int)numericUpDownNumberMaximum.Value;
progressBar.Value = 0;
progressBar.Step = 1;
backgroundWorker.RunWorkerAsync();
}
private void ButtonCopyList_Click(object sender, EventArgs e)
{
textBoxList.SelectAll();
textBoxList.Copy();
MessageBox.Show(text: "Die Liste wurde in die Zwischenablage kopiert.");
}
private void ButtonSaveList_Click(object sender, EventArgs e)
{
using SaveFileDialog save = new()
{
FileName = "liste.txt",
Filter = "Textdatei | *.txt"
};
if (save.ShowDialog() == DialogResult.OK)
{
using StreamWriter writer = new(stream: save.OpenFile());
try
{
writer.WriteLine(value: textBoxList.Text);
}
finally
{
writer.Close();
MessageBox.Show(text: "Die Liste wurde in die Textdatei kopiert.");
}
}
}
private void ButtonDeleteList_Click(object sender, EventArgs e)
{
textBoxList.Clear();
timeSpan = TimeSpan.Zero;
UpdateStatusBarStatistic();
}
private void ButtonCreateList_Click(object sender, EventArgs e)
{
DisableControls();
ButtonDeleteList_Click(sender: sender, e: e);
ButtonAddToList_Click(sender: sender, e: e);
}
private void ButtonUndo_Click(object sender, EventArgs e)
{
textBoxList.Text = backupListUndo;
buttonUndo.Enabled = false;
buttonRedo.Enabled = true;
toolStripMenuItemListUndo.Enabled = false;
toolStripMenuItemListRedo.Enabled = true;
UpdateStatusBarStatistic();
}
private void ButtonRedo_Click(object sender, EventArgs e)
{
textBoxList.Text = backupListRedo;
buttonUndo.Enabled = true;
buttonRedo.Enabled = false;
toolStripMenuItemListUndo.Enabled = true;
toolStripMenuItemListRedo.Enabled = false;
UpdateStatusBarStatistic();
}
private void BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
for (int i = (int)numericUpDownNumberMinimum.Value; i < (int)numericUpDownNumberMaximum.Value + 1; i++)
{
if (textBoxList.Text.Length > 0)
{
textBoxList.AppendText(text: Environment.NewLine);
}
if (checkBoxFillWithZeros.Checked)
{
textBoxList.AppendText(text: $"{textBoxStringBeforeNumber.Text}{i.ToString().PadLeft(totalWidth: ((int)numericUpDownNumberMaximum.Value).ToString().Length, paddingChar: '0')}{textBoxStringAfterNumber.Text}");
}
else
{
textBoxList.AppendText(text: $"{textBoxStringBeforeNumber.Text}{i}{textBoxStringAfterNumber.Text}");
}
backgroundWorker.ReportProgress(percentProgress: i);
endTime = DateTime.Now;
timeSpan = endTime - startTime;
UpdateStatusBarStatistic();
backupListRedo = textBoxList.Text;
}
}
private void BackgroundWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) => progressBar.PerformStep();
private void ToolStripStatusLabelSize_Click(object sender, EventArgs e)
{
if (toolStripStatusLabelSize.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelSize.ForeColor = SystemColors.GrayText;
toolStripStatusLabelSize.Text = toolStripStatusLabelSize.Tag.ToString();
}
else
{
toolStripStatusLabelSize.ForeColor = SystemColors.ControlText;
}
}
private void ToolStripStatusLabelLines_Click(object sender, EventArgs e)
{
if (toolStripStatusLabelLines.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelLines.ForeColor = SystemColors.GrayText;
toolStripStatusLabelLines.Text = toolStripStatusLabelLines.Tag.ToString();
}
else
{
toolStripStatusLabelLines.ForeColor = SystemColors.ControlText;
}
}
private void ToolStripStatusLabelTimeSpan_Click(object sender, EventArgs e)
{
if (toolStripStatusLabelTimeSpan.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelTimeSpan.ForeColor = SystemColors.GrayText;
toolStripStatusLabelTimeSpan.Text = toolStripStatusLabelTimeSpan.Tag.ToString();
}
else
{
toolStripStatusLabelTimeSpan.ForeColor = SystemColors.ControlText;
}
}
private void ToolStripStatusLabelLim_Click(object sender, EventArgs e)
{
if (toolStripStatusLabelLim.ForeColor == SystemColors.ControlText)
{
toolStripStatusLabelLim.ForeColor = SystemColors.GrayText;
toolStripStatusLabelLim.Text = toolStripStatusLabelLim.Tag.ToString();
}
else
{
toolStripStatusLabelLim.ForeColor = SystemColors.ControlText;
}
}
private void ToolStripStatusLabelStyle_Click(object sender, EventArgs e)
{
Application.VisualStyleState = Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled
? VisualStyleState.NoneEnabled
: VisualStyleState.ClientAndNonClientAreasEnabled;
Invalidate(invalidateChildren: true);
}
private void BackgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) => EnableControls();
private void ToolStripMenuItemInfo_Click(object sender, EventArgs e)
{
using AboutBoxForm formAboutBox = new();
formAboutBox.TopMost = TopMost;
formAboutBox.ShowDialog();
}
private void ToolStripMenuItemLicense_Click(object sender, EventArgs e)
{
//LicenseForm
using LicenseForm formLicense = new();
formLicense.TopMost = TopMost;
formLicense.ShowDialog();
}
private void ToolStripMenuItemExit_Click(object sender, EventArgs e) => Close();
private void ToolStripMenuItemListCreate_Click(object sender, EventArgs e) => ButtonCreateList_Click(sender: sender, e: e);
private void ToolStripMenuItemListAdd_Click(object sender, EventArgs e) => ButtonAddToList_Click(sender: sender, e: e);
private void ToolStripMenuItemListDelete_Click(object sender, EventArgs e) => ButtonDeleteList_Click(sender: sender, e: e);
private void ToolStripMenuItemListUndo_Click(object sender, EventArgs e) => ButtonUndo_Click(sender: sender, e: e);
private void ToolStripMenuItemListRedo_Click(object sender, EventArgs e) => ButtonRedo_Click(sender: sender, e: e);
private void ToolStripMenuItemListCopy_Click(object sender, EventArgs e) => ButtonCopyList_Click(sender: sender, e: e);
private void ToolStripMenuItemListSave_Click(object sender, EventArgs e) => ButtonSaveList_Click(sender: sender, e: e);
private void ToolStripMenuItemSettingsDisableVisualStyle_Click(object sender, EventArgs e) => ToolStripStatusLabelStyle_Click(sender: sender, e: e);
private void ToolStripMenuItemSettingsStayOnTop_Click(object sender, EventArgs e) => CheckStayOnTop();
}
}