Repository navigation
Expand file tree
/
Copy pathModernConfirmationDialog.cs
More file actions
838 lines (747 loc) · 37 KB
/
Copy pathModernConfirmationDialog.cs
File metadata and controls
838 lines (747 loc) · 37 KB
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
// Design-Rule / UI consistency:
// Keep layout, spacing, colors, sizes, and fonts aligned with ModernTheme.
// Add new shared visual values to ModernTheme instead of hardcoding local exceptions here.
// 03.05.2026 /dc
using System;
using System.Drawing;
using System.Windows.Forms;
// Semantic Anchor [ModernConfirmationDialog.cs]: Destructive-action confirmations must preserve explicit user choice; the dialog must not perform the underlying destructive operation.
// Semantic Anchor [Dialog animation consistency]: ThemeBackdropLabel renders text over
// ModernWindowFrame's cached effect frame; no dialog state, handlers, or layout change.
namespace EasyVersionBackup
{
public static class ModernConfirmationDialog
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool ReleaseCapture();
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
public static DialogResult Show(
Form owner,
string title,
string message,
Size? clientSize = null)
{
using Form form = new ThemeBufferedForm();
form.Text = title;
form.StartPosition = FormStartPosition.CenterParent;
form.FormBorderStyle = FormBorderStyle.None;
form.ClientSize =
clientSize ??
new Size(420, 200);
form.BackColor = ModernTheme.WindowBackColor;
form.Font = new Font(ModernTheme.FontFamilyName, ModernTheme.DefaultFontSize);
form.ShowInTaskbar = false;
form.Icon = owner.Icon;
ModernWindowFrame.Apply(form);
Panel panelModernTitleBar = new ThemeTitleBarPanel
{
Name = "panelModernTitleBar",
Dock = DockStyle.Top,
Height = ModernTheme.TitleBarHeight,
BackColor = ModernTheme.TitleBarBackColor
};
PictureBox pictureBoxModernTitleIcon = new PictureBox
{
Name = "pictureBoxModernTitleIcon",
Location = new Point(ModernTheme.TitleBarIconLeft, ModernTheme.TitleBarIconTop),
Size = new Size(ModernTheme.TitleBarIconSize, ModernTheme.TitleBarIconSize),
SizeMode = PictureBoxSizeMode.StretchImage,
Image = owner.Icon?.ToBitmap(),
BackColor = Color.Transparent
};
Label labelModernTitle = new ThemeBackdropLabel
{
Name = "labelModernTitle",
Text = title,
AutoSize = false,
Location = new Point(ModernTheme.TitleBarTextLeft, 0),
Size = new Size(form.ClientSize.Width - 66, ModernTheme.TitleBarHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
TextAlign = ContentAlignment.MiddleLeft,
ForeColor = ModernTheme.TextColor,
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.TitleFontSize, FontStyle.Regular),
BackColor = Color.Transparent
};
Button buttonModernClose = CreateModernTitleBarButton(
form,
"buttonModernClose",
new Point(form.ClientSize.Width - ModernTheme.TitleBarButtonSize.Width, 0));
buttonModernClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonModernClose.MouseEnter += (sender, e) => buttonModernClose.BackColor = ModernTheme.CloseButtonHoverColor;
buttonModernClose.MouseLeave += (sender, e) => buttonModernClose.BackColor = ModernTheme.TitleBarBackColor;
buttonModernClose.Click += (sender, e) =>
{
form.DialogResult = DialogResult.No;
form.Close();
};
panelModernTitleBar.MouseDown += (sender, e) => MoveDialogWindow(form, e);
pictureBoxModernTitleIcon.MouseDown += (sender, e) => MoveDialogWindow(form, e);
labelModernTitle.MouseDown += (sender, e) => MoveDialogWindow(form, e);
panelModernTitleBar.Controls.Add(pictureBoxModernTitleIcon);
panelModernTitleBar.Controls.Add(labelModernTitle);
panelModernTitleBar.Controls.Add(buttonModernClose);
int buttonTop =
form.ClientSize.Height -
ModernTheme.DialogButtonSize.Height -
21;
Label labelMessage = new ThemeBackdropLabel
{
Text = message,
AutoSize = false,
Location = new Point(18, 52),
Size = new Size(
form.ClientSize.Width - 36,
buttonTop - 64),
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft
};
Button buttonYes = new ThemeContrastButton
{
Text = "Yes",
Size = ModernTheme.DialogButtonSize,
Location = new Point(
form.ClientSize.Width - 168,
buttonTop),
DialogResult = DialogResult.Yes,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.AccentColor,
ForeColor = ModernTheme.DarkTextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter, // Button-Text positioning
Padding = ModernTheme.DialogPrimaryButtonTextPadding, // Button-Text positioning
UseCompatibleTextRendering = true, // Button-Text positioning
UseVisualStyleBackColor = false
};
buttonYes.FlatAppearance.BorderSize = 0;
buttonYes.FlatAppearance.MouseOverBackColor = ModernTheme.AccentHoverColor;
buttonYes.FlatAppearance.MouseDownBackColor = ModernTheme.ControlBackColor;
Button buttonNo = new ThemeContrastButton
{
Text = "No",
Size = ModernTheme.DialogButtonSize,
Location = new Point(
form.ClientSize.Width - 87,
buttonTop),
DialogResult = DialogResult.No,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter, // Button-Text positioning
Padding = ModernTheme.DialogSecondaryButtonTextPadding, // Button-Text positioning
UseCompatibleTextRendering = true, // Button-Text positioning
UseVisualStyleBackColor = false
};
buttonNo.FlatAppearance.BorderColor = ModernTheme.AccentColor;
buttonNo.FlatAppearance.BorderSize = 1;
buttonNo.FlatAppearance.MouseOverBackColor = ModernTheme.ControlHoverBackColor;
buttonNo.FlatAppearance.MouseDownBackColor = ModernTheme.AccentColor;
form.Controls.Add(panelModernTitleBar);
form.Controls.Add(labelMessage);
form.Controls.Add(buttonYes);
form.Controls.Add(buttonNo);
form.AcceptButton = buttonYes;
form.CancelButton = buttonNo;
return form.ShowDialog(owner);
}
public static DialogResult ShowInitialDisclaimer(
Form owner)
{
const string requiredText =
"I ACCEPT";
const string disclaimerText =
"Important Information and Disclaimer\r\n" +
"\r\n" +
"Experimental Software – Please Read Before Use\r\n" +
"\r\n" +
"EasyVersionBackup is an independently developed, experimental software project intended for personal use, testing, and evaluation.\r\n" +
"\r\n" +
"The software is designed to create and manage file backups. However, like any backup solution, it may contain defects or behave unexpectedly under certain conditions.\r\n" +
"\r\n" +
"Important Considerations\r\n" +
"\r\n" +
"Although the software is developed with care, it has not undergone formal certification, independent security auditing, or comprehensive validation for business-critical or regulated environments.\r\n" +
"\r\n" +
"Certain functions, including backup synchronization, retention, cleanup, and file replacement, may modify or delete existing files as part of their intended operation.\r\n" +
"\r\n" +
"Incorrect settings, software defects, interrupted operations, or unexpected system conditions could potentially result in incomplete backups or unintended data loss.\r\n" +
"\r\n" +
"To minimize these risks, we recommend:\r\n" +
"\r\n" +
" Verifying backup configurations before relying on them.\r\n" +
" Testing backup and restore operations with non-critical data.\r\n" +
" Maintaining an additional, independent backup of important files.\r\n" +
" Reviewing retention and cleanup settings carefully.\r\n" +
"\r\n" +
"Warranty and Liability\r\n" +
"\r\n" +
"This software is provided \"AS IS\", without warranties of any kind, express or implied, to the extent permitted by applicable law.\r\n" +
"\r\n" +
"The author does not guarantee uninterrupted operation, error-free functionality, successful backups, or the recoverability of stored data.\r\n" +
"\r\n" +
"To the extent permitted by applicable law, the author shall not be liable for losses or damages resulting from the use or inability to use this software, including loss of data.\r\n" +
"\r\n" +
"Nothing in this disclaimer excludes or limits liability where such exclusion or limitation is prohibited by applicable law.\r\n" +
"\r\n" +
"Acknowledgment\r\n" +
"\r\n" +
"By continuing, you confirm that you understand the experimental nature of this software, the potential risks associated with backup and file-management operations, and the importance of maintaining independent backups of valuable data.\r\n" +
"\r\n" +
"Required confirmation:\r\n" +
"\r\n" +
"I ACCEPT";
using Form form = new ThemeBufferedForm();
form.Text = "Important Information and Disclaimer";
form.StartPosition = FormStartPosition.CenterParent;
form.FormBorderStyle = FormBorderStyle.None;
form.ClientSize = new Size(820, 700);
form.BackColor = ModernTheme.WindowBackColor;
form.Font = new Font(ModernTheme.FontFamilyName, ModernTheme.DefaultFontSize);
form.ShowInTaskbar = false;
form.Icon = owner.Icon;
ModernWindowFrame.Apply(form);
Panel panelModernTitleBar = new ThemeTitleBarPanel
{
Name = "panelModernTitleBar",
Dock = DockStyle.Top,
Height = ModernTheme.TitleBarHeight,
BackColor = ModernTheme.TitleBarBackColor
};
PictureBox pictureBoxModernTitleIcon = new PictureBox
{
Name = "pictureBoxModernTitleIcon",
Location = new Point(ModernTheme.TitleBarIconLeft, ModernTheme.TitleBarIconTop),
Size = new Size(ModernTheme.TitleBarIconSize, ModernTheme.TitleBarIconSize),
SizeMode = PictureBoxSizeMode.StretchImage,
Image = owner.Icon?.ToBitmap(),
BackColor = Color.Transparent
};
Label labelModernTitle = new ThemeBackdropLabel
{
Name = "labelModernTitle",
Text = "Important Information and Disclaimer",
AutoSize = false,
Location = new Point(ModernTheme.TitleBarTextLeft, 0),
Size = new Size(form.ClientSize.Width - 66, ModernTheme.TitleBarHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
TextAlign = ContentAlignment.MiddleLeft,
ForeColor = ModernTheme.TextColor,
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.TitleFontSize, FontStyle.Regular),
BackColor = Color.Transparent
};
Button buttonModernClose = CreateModernTitleBarButton(
form,
"buttonModernClose",
new Point(form.ClientSize.Width - ModernTheme.TitleBarButtonSize.Width, 0));
buttonModernClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonModernClose.MouseEnter += (sender, e) => buttonModernClose.BackColor = ModernTheme.CloseButtonHoverColor;
buttonModernClose.MouseLeave += (sender, e) => buttonModernClose.BackColor = ModernTheme.TitleBarBackColor;
buttonModernClose.Click += (sender, e) =>
{
form.DialogResult = DialogResult.Cancel;
form.Close();
};
panelModernTitleBar.MouseDown += (sender, e) => MoveDialogWindow(form, e);
pictureBoxModernTitleIcon.MouseDown += (sender, e) => MoveDialogWindow(form, e);
labelModernTitle.MouseDown += (sender, e) => MoveDialogWindow(form, e);
panelModernTitleBar.Controls.Add(pictureBoxModernTitleIcon);
panelModernTitleBar.Controls.Add(labelModernTitle);
panelModernTitleBar.Controls.Add(buttonModernClose);
TextBox textBoxDisclaimer = new TextBox
{
Name = "textBoxDisclaimer",
Location = new Point(18, 52),
Size = new Size(form.ClientSize.Width - 36, 520),
Multiline = true,
ReadOnly = true,
ScrollBars = ScrollBars.Vertical,
WordWrap = true,
Text = disclaimerText,
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
BorderStyle = BorderStyle.FixedSingle,
TabStop = false
};
Label labelRequiredPrompt = new ThemeBackdropLabel
{
Text = "Type the following text in UPPERCASE to accept:",
AutoSize = false,
Location = new Point(18, 582),
Size = new Size(form.ClientSize.Width - 36, 22),
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft
};
Label labelRequiredText = new ThemeBackdropLabel
{
Text = requiredText,
AutoSize = false,
Location = new Point(18, 604),
Size = new Size(form.ClientSize.Width - 36, 26),
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft,
Font = new Font(
ModernTheme.FontFamilyName,
ModernTheme.DefaultFontSize,
FontStyle.Bold)
};
TextBox textBoxConfirmation = new TextBox
{
Name = "textBoxConfirmation",
Location = new Point(18, 632),
Size = new Size(form.ClientSize.Width - 204, 27),
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
BorderStyle = BorderStyle.FixedSingle
};
Button buttonAccept = new ThemeContrastButton
{
Text = "Accept",
Size = ModernTheme.DialogButtonSize,
Location = new Point(form.ClientSize.Width - 168, 631),
DialogResult = DialogResult.OK,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.AccentColor,
ForeColor = ModernTheme.DarkTextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = ModernTheme.DialogPrimaryButtonTextPadding,
UseCompatibleTextRendering = true,
UseVisualStyleBackColor = false,
Enabled = false
};
buttonAccept.FlatAppearance.BorderSize = 0;
buttonAccept.FlatAppearance.MouseOverBackColor = ModernTheme.AccentHoverColor;
buttonAccept.FlatAppearance.MouseDownBackColor = ModernTheme.ControlBackColor;
Button buttonDecline = new ThemeContrastButton
{
Text = "Decline",
Size = ModernTheme.DialogButtonSize,
Location = new Point(form.ClientSize.Width - 87, 631),
DialogResult = DialogResult.Cancel,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = ModernTheme.DialogSecondaryButtonTextPadding,
UseCompatibleTextRendering = true,
UseVisualStyleBackColor = false
};
buttonDecline.FlatAppearance.BorderColor = ModernTheme.AccentColor;
buttonDecline.FlatAppearance.BorderSize = 1;
buttonDecline.FlatAppearance.MouseOverBackColor = ModernTheme.ControlHoverBackColor;
buttonDecline.FlatAppearance.MouseDownBackColor = ModernTheme.AccentColor;
textBoxConfirmation.TextChanged += (sender, e) =>
{
buttonAccept.Enabled =
string.Equals(
textBoxConfirmation.Text,
requiredText,
StringComparison.Ordinal);
};
form.Controls.Add(panelModernTitleBar);
form.Controls.Add(textBoxDisclaimer);
form.Controls.Add(labelRequiredPrompt);
form.Controls.Add(labelRequiredText);
form.Controls.Add(textBoxConfirmation);
form.Controls.Add(buttonAccept);
form.Controls.Add(buttonDecline);
form.AcceptButton = buttonAccept;
form.CancelButton = buttonDecline;
DialogResult result =
form.ShowDialog(owner);
if (result == DialogResult.OK)
{
SystemLogger.WriteInitialDisclaimerConfirmation(
textBoxConfirmation.Text);
}
return result;
}
public static DialogResult ShowRecurringDataLossWarning(
Form owner,
bool retentionEnabled,
bool sourceCleanupEnabled)
{
const string requiredText =
"I understand the risk of data loss!";
string enabledFeatures =
retentionEnabled &&
sourceCleanupEnabled
? "Retention and Source Cleanup are enabled."
: retentionEnabled
? "Retention is enabled."
: "Source Cleanup is enabled.";
DialogResult result =
ShowTextConfirmation(
owner,
"Data-loss warning",
enabledFeatures + " These experimental features can permanently, unintentionally, and irreversibly delete backup or source data. " +
"Deleted data cannot be restored by EasyVersionBackup. Their use is expressly discouraged. " +
"Verify all configured paths, rules, exclusions, and retention settings. Keep an independent, complete, readable, and recoverable backup that is not accessible to EasyVersionBackup. " +
"DO NOT RELY ON EASYVERSIONBACKUP AS YOUR ONLY BACKUP. NO WARRANTY OR GUARANTEE OF ANY KIND IS PROVIDED. " +
"THE AUTHOR ASSUMES NO RESPONSIBILITY OR LIABILITY FOR DATA LOSS, CORRUPTION, DELETION, LOSS OF BACKUPS, CONSEQUENTIAL DAMAGE, OR ANY OTHER DAMAGE RESULTING FROM USING THESE FEATURES.",
requiredText,
new Size(620, 470));
SystemLogger.WriteRecurringDataLossWarning(
retentionEnabled,
sourceCleanupEnabled,
result == DialogResult.OK,
result == DialogResult.OK
? requiredText
: string.Empty);
return result;
}
// Semantic Anchor: Experimental feature activation is explicit, themed, and independent of Debug Mode.
public static DialogResult ShowExperimentalDataLossConfirmation(
Form owner,
string featureName,
string deletionDescription)
{
string message = featureName == "Retention"
? "Retention automatically removes older backup versions according to your configured retention policy. " +
"Deleted versions may no longer be recoverable. Review your retention settings and keep an independent backup of important files."
: "Source Cleanup removes files from the original source directory after a successful backup, according to your configuration. " +
"Deleted source files may no longer be recoverable from their original location. Check your source and destination paths and make sure the backup is accessible.";
message += "\n\nThis is an experimental feature. By enabling it, you acknowledge the possible consequences of deletion " +
"and accept responsibility for your configuration. The software is provided AS IS, without warranties, " +
"to the extent permitted by applicable law. Nothing excludes liability where exclusion is prohibited by law.";
using Form form = new ThemeBufferedForm
{
Text = "Enable " + featureName + "?",
StartPosition = FormStartPosition.CenterParent,
FormBorderStyle = FormBorderStyle.None,
ClientSize = new Size(620, 340),
BackColor = ModernTheme.WindowBackColor,
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.DefaultFontSize),
ShowInTaskbar = false,
Icon = owner.Icon
};
ModernWindowFrame.Apply(form);
// Semantic Anchor [Security dialog repaint]: Buffered caption shares the
// same form frame; confirmation text and acceptance requirements are unchanged.
Panel titleBar = new ThemeTitleBarPanel
{
Name = "panelTitleBar",
Dock = DockStyle.Top,
Height = ModernTheme.TitleBarHeight,
BackColor = ModernTheme.TitleBarBackColor
};
Label title = new ThemeBackdropLabel
{
Text = form.Text,
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.TitleFontSize),
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleLeft,
Padding = new Padding(ModernTheme.TitleBarTextLeft, 0, 0, 0)
};
titleBar.Controls.Add(title);
form.Controls.Add(titleBar);
Label description = new ThemeBackdropLabel
{
Text = message,
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
Location = new Point(18, ModernTheme.TitleBarHeight + 18),
Size = new Size(form.ClientSize.Width - 36, 168),
TextAlign = ContentAlignment.TopLeft
};
const string requiredText = "I ACCEPT";
Label acknowledgmentPrompt = new ThemeBackdropLabel
{
Text = "Type I ACCEPT (UPPERCASE) to enable this feature:",
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
AutoSize = true,
Location = new Point(18, form.ClientSize.Height - 119)
};
TextBox acknowledgment = new TextBox
{
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(18, form.ClientSize.Height - 91),
Size = new Size(form.ClientSize.Width - 36, 27)
};
Button enable = ModernTheme.CreateDialogPrimaryButton("buttonEnable", "Enable");
Button cancel = ModernTheme.CreateDialogSecondaryButton("buttonCancel", "Cancel", DialogResult.Cancel);
enable.Enabled = false;
acknowledgment.TextChanged += (_, _) =>
enable.Enabled = string.Equals(acknowledgment.Text, requiredText, StringComparison.Ordinal);
enable.Click += (_, _) =>
{
if (string.Equals(acknowledgment.Text, requiredText, StringComparison.Ordinal))
{
form.DialogResult = DialogResult.OK;
form.Close();
}
};
cancel.Click += (_, _) =>
{
form.DialogResult = DialogResult.Cancel;
form.Close();
};
form.Controls.Add(description);
form.Controls.Add(acknowledgmentPrompt);
form.Controls.Add(acknowledgment);
form.Controls.Add(enable);
form.Controls.Add(cancel);
ModernTheme.PositionDialogButtons(form, enable, cancel);
DialogResult result = form.ShowDialog(owner);
if (result == DialogResult.OK)
{
SystemLogger.WriteExperimentalConfirmation(featureName, requiredText);
}
return result;
}
public static DialogResult ShowTextConfirmation(
Form owner,
string title,
string message,
string requiredText,
Size clientSize)
{
using Form form = new ThemeBufferedForm();
form.Text = title;
form.StartPosition = FormStartPosition.CenterParent;
form.FormBorderStyle = FormBorderStyle.None;
form.ClientSize = clientSize;
form.BackColor = ModernTheme.WindowBackColor;
form.Font = new Font(ModernTheme.FontFamilyName, ModernTheme.DefaultFontSize);
form.ShowInTaskbar = false;
form.Icon = owner.Icon;
ModernWindowFrame.Apply(form);
int contentWidth =
form.ClientSize.Width -
36;
Size measuredMessageSize =
TextRenderer.MeasureText(
message,
form.Font,
new Size(
contentWidth,
int.MaxValue),
TextFormatFlags.WordBreak |
TextFormatFlags.NoPadding);
int messageTop = 52;
int messageHeight =
measuredMessageSize.Height +
24;
int promptTop =
messageTop +
messageHeight +
14;
int requiredTextTop =
promptTop +
24;
int textBoxTop =
requiredTextTop +
28;
int minimumClientHeight =
textBoxTop +
27 +
82;
if (form.ClientSize.Height < minimumClientHeight)
{
form.ClientSize =
new Size(
form.ClientSize.Width,
minimumClientHeight);
}
Panel panelModernTitleBar = new ThemeTitleBarPanel
{
Name = "panelModernTitleBar",
Dock = DockStyle.Top,
Height = ModernTheme.TitleBarHeight,
BackColor = ModernTheme.TitleBarBackColor
};
PictureBox pictureBoxModernTitleIcon = new PictureBox
{
Name = "pictureBoxModernTitleIcon",
Location = new Point(ModernTheme.TitleBarIconLeft, ModernTheme.TitleBarIconTop),
Size = new Size(ModernTheme.TitleBarIconSize, ModernTheme.TitleBarIconSize),
SizeMode = PictureBoxSizeMode.StretchImage,
Image = owner.Icon?.ToBitmap(),
BackColor = Color.Transparent
};
Label labelModernTitle = new ThemeBackdropLabel
{
Name = "labelModernTitle",
Text = title,
AutoSize = false,
Location = new Point(ModernTheme.TitleBarTextLeft, 0),
Size = new Size(form.ClientSize.Width - 66, ModernTheme.TitleBarHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
TextAlign = ContentAlignment.MiddleLeft,
ForeColor = ModernTheme.TextColor,
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.TitleFontSize, FontStyle.Regular),
BackColor = Color.Transparent
};
Button buttonModernClose = CreateModernTitleBarButton(
form,
"buttonModernClose",
new Point(form.ClientSize.Width - ModernTheme.TitleBarButtonSize.Width, 0));
buttonModernClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonModernClose.MouseEnter += (sender, e) => buttonModernClose.BackColor = ModernTheme.CloseButtonHoverColor;
buttonModernClose.MouseLeave += (sender, e) => buttonModernClose.BackColor = ModernTheme.TitleBarBackColor;
buttonModernClose.Click += (sender, e) =>
{
form.DialogResult = DialogResult.Cancel;
form.Close();
};
panelModernTitleBar.MouseDown += (sender, e) => MoveDialogWindow(form, e);
pictureBoxModernTitleIcon.MouseDown += (sender, e) => MoveDialogWindow(form, e);
labelModernTitle.MouseDown += (sender, e) => MoveDialogWindow(form, e);
panelModernTitleBar.Controls.Add(pictureBoxModernTitleIcon);
panelModernTitleBar.Controls.Add(labelModernTitle);
panelModernTitleBar.Controls.Add(buttonModernClose);
Label labelMessage = new ThemeBackdropLabel
{
Text = message,
AutoSize = false,
Location = new Point(18, messageTop),
Size = new Size(contentWidth, messageHeight),
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.TopLeft
};
Label labelRequiredPrompt = new ThemeBackdropLabel
{
Text = "Type the following text to continue:",
AutoSize = false,
Location = new Point(18, promptTop),
Size = new Size(contentWidth, 24),
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft
};
Label labelRequiredText = new ThemeBackdropLabel
{
Text = requiredText,
AutoSize = false,
Location = new Point(18, requiredTextTop),
Size = new Size(contentWidth, 28),
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft,
Font = new Font(
ModernTheme.FontFamilyName,
ModernTheme.DefaultFontSize,
FontStyle.Bold)
};
TextBox textBoxConfirmation = new TextBox
{
Name = "textBoxConfirmation",
Location = new Point(18, textBoxTop),
Size = new Size(contentWidth, 27),
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
BorderStyle = BorderStyle.FixedSingle
};
Button buttonConfirm = new ThemeContrastButton
{
Text = "Enable",
Size = ModernTheme.DialogButtonSize,
Location = new Point(form.ClientSize.Width - 168, form.ClientSize.Height - 49),
DialogResult = DialogResult.OK,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.AccentColor,
ForeColor = ModernTheme.DarkTextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = ModernTheme.DialogPrimaryButtonTextPadding,
UseCompatibleTextRendering = true,
UseVisualStyleBackColor = false,
Enabled = false
};
buttonConfirm.FlatAppearance.BorderSize = 0;
buttonConfirm.FlatAppearance.MouseOverBackColor = ModernTheme.AccentHoverColor;
buttonConfirm.FlatAppearance.MouseDownBackColor = ModernTheme.ControlBackColor;
Button buttonCancel = new ThemeContrastButton
{
Text = "Cancel",
Size = ModernTheme.DialogButtonSize,
Location = new Point(form.ClientSize.Width - 87, form.ClientSize.Height - 49),
DialogResult = DialogResult.Cancel,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.ControlBackColor,
ForeColor = ModernTheme.TextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = ModernTheme.DialogSecondaryButtonTextPadding,
UseCompatibleTextRendering = true,
UseVisualStyleBackColor = false
};
buttonCancel.FlatAppearance.BorderColor = ModernTheme.AccentColor;
buttonCancel.FlatAppearance.BorderSize = 1;
buttonCancel.FlatAppearance.MouseOverBackColor = ModernTheme.ControlHoverBackColor;
buttonCancel.FlatAppearance.MouseDownBackColor = ModernTheme.AccentColor;
textBoxConfirmation.TextChanged += (sender, e) =>
{
buttonConfirm.Enabled =
string.Equals(
textBoxConfirmation.Text,
requiredText,
StringComparison.Ordinal);
};
form.Controls.Add(panelModernTitleBar);
form.Controls.Add(labelMessage);
form.Controls.Add(labelRequiredPrompt);
form.Controls.Add(labelRequiredText);
form.Controls.Add(textBoxConfirmation);
form.Controls.Add(buttonConfirm);
form.Controls.Add(buttonCancel);
form.AcceptButton = buttonConfirm;
form.CancelButton = buttonCancel;
return form.ShowDialog(owner);
}
private static Button CreateModernTitleBarButton(Form form, string name, Point location)
{
Button button = new ThemeTitleBarButton
{
Name = name,
Text = string.Empty,
Size = ModernTheme.TitleBarButtonSize,
Location = location,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.TitleBarBackColor,
ForeColor = ModernTheme.TextColor,
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = Padding.Empty,
UseVisualStyleBackColor = false
};
button.FlatAppearance.BorderSize = 0;
button.FlatAppearance.MouseOverBackColor = ModernTheme.ControlBackColor;
button.FlatAppearance.MouseDownBackColor = ModernTheme.AccentColor;
button.Paint += (sender, e) =>
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using Pen pen = new Pen(ModernTheme.TextColor, 1.4F)
{
StartCap = System.Drawing.Drawing2D.LineCap.Square,
EndCap = System.Drawing.Drawing2D.LineCap.Square
};
e.Graphics.DrawLine(pen, 13, 11, 23, 21);
e.Graphics.DrawLine(pen, 23, 11, 13, 21);
};
return button;
}
private static void MoveDialogWindow(Form form, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
const int wmNclbuttondown = 0xA1;
const int htCaption = 0x2;
ReleaseCapture();
SendMessage(form.Handle, wmNclbuttondown, htCaption, 0);
}
}
}