-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathInformationBoxForm.cs
More file actions
1803 lines (1572 loc) · 66.4 KB
/
InformationBoxForm.cs
File metadata and controls
1803 lines (1572 loc) · 66.4 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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// <copyright file="InformationBoxForm.cs" company="Johann Blais">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Johann Blais</author>
// <summary>Displays a message box that can contain text, buttons, and symbols that inform and instruct the user</summary>
namespace InfoBox
{
using InfoBox.Controls;
using InfoBox.Internals;
using InfoBox.Properties;
using System;
using System.Drawing;
using System.Globalization;
using System.Media;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
/// <summary>
/// Displays a message box that can contain text, buttons, and symbols that inform and instruct the user.
/// </summary>
internal partial class InformationBoxForm : Form
{
#region Consts
/// <summary>
/// Width of the icon panel
/// </summary>
private const int IconPanelWidth = 68;
/// <summary>
/// Padding for the borders
/// </summary>
private const int BorderPadding = 20;
#endregion Consts
#region Attributes
/// <summary>
/// Contains the callback used to inform the caller of a modeless box
/// </summary>
private readonly AsyncResultCallback callback;
/// <summary>
/// Text for the first user button
/// </summary>
private readonly string buttonUser1Text = "User1";
/// <summary>
/// Text for the second user button
/// </summary>
private readonly string buttonUser2Text = "User2";
/// <summary>
/// Text for the third user button
/// </summary>
private readonly string buttonUser3Text = "User3";
/// <summary>
/// Help file associated to the help button
/// </summary>
private readonly string helpFile;
/// <summary>
/// Help topic associated to the help button
/// </summary>
private readonly string helpTopic;
/// <summary>
/// Text for the "Do not show again" checkbox
/// </summary>
private readonly string doNotShowAgainText;
/// <summary>
/// Contains the graphics used to measure the strings
/// </summary>
private readonly Graphics measureGraphics;
/// <summary>
/// Contains a reference to the active form
/// </summary>
private readonly Form activeForm;
/// <summary>
/// Result corresponding the clicked button
/// </summary>
private InformationBoxResult result = InformationBoxResult.None;
/// <summary>
/// Main icon of the form
/// </summary>
private InformationBoxIcon icon;
/// <summary>
/// Custom icon
/// </summary>
private Icon customIcon;
/// <summary>
/// Buttons displayed on the form
/// </summary>
private InformationBoxButtons buttons;
/// <summary>
/// Default button
/// </summary>
private InformationBoxDefaultButton defaultButton;
/// <summary>
/// Buttons layout
/// </summary>
private InformationBoxButtonsLayout buttonsLayout = InformationBoxButtonsLayout.GroupMiddle;
/// <summary>
/// Contains the autosize mode
/// </summary>
private InformationBoxAutoSizeMode autoSizeMode = InformationBoxAutoSizeMode.None;
/// <summary>
/// Contains the box initial position
/// </summary>
private InformationBoxPosition position = InformationBoxPosition.CenterOnParent;
/// <summary>
/// Contains a value defining whether displaying the checkbox or not
/// </summary>
private InformationBoxCheckBox checkBox = 0;
/// <summary>
/// Contains the style of the box
/// </summary>
private InformationBoxStyle style = InformationBoxStyle.Standard;
/// <summary>
/// Contains the autoclose parameters
/// </summary>
private AutoCloseParameters autoClose;
/// <summary>
/// Contains the design parameters
/// </summary>
private DesignParameters design;
/// <summary>
/// Contains the font parameters
/// </summary>
private FontParameters fontParameters;
/// <summary>
/// Contains the style of the title
/// </summary>
private InformationBoxTitleIconStyle titleStyle = InformationBoxTitleIconStyle.None;
/// <summary>
/// Contains the title icon
/// </summary>
private Icon titleIcon;
/// <summary>
/// Contains if the box is modal or not
/// </summary>
private InformationBoxBehavior behavior = InformationBoxBehavior.Modal;
/// <summary>
/// Contains the opacity of the form
/// </summary>
private InformationBoxOpacity opacity = InformationBoxOpacity.NoFade;
/// <summary>
/// Contains the icon type
/// </summary>
private IconType iconType = IconType.Internal;
/// <summary>
/// Contains the text
/// </summary>
private StringBuilder internalText;
/// <summary>
/// Contains if the help button should be displayed
/// </summary>
private bool showHelpButton;
/// <summary>
/// Help navigator associated to the help button
/// </summary>
private HelpNavigator helpNavigator = HelpNavigator.TableOfContents;
/// <summary>
/// Contains whether a mouse button is down
/// </summary>
private bool mouseDown;
/// <summary>
/// Last stored pointer position
/// </summary>
private Point lastPointerPosition;
/// <summary>
/// Elapsed time for the autoclose
/// </summary>
private int elapsedTime;
/// <summary>
/// Z-Order of the form
/// </summary>
private InformationBoxOrder order = InformationBoxOrder.Default;
/// <summary>
/// Sound to play on opening
/// </summary>
private InformationBoxSound sound;
#endregion Attributes
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="InformationBoxForm"/> class using the specified text.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="title">The title.</param>
/// <param name="helpFile">The help file.</param>
/// <param name="helpTopic">The help topic.</param>
/// <param name="initialization">The initialization.</param>
/// <param name="buttons">The buttons.</param>
/// <param name="icon">The icon.</param>
/// <param name="customIcon">The custom icon.</param>
/// <param name="defaultButton">The default button.</param>
/// <param name="customButtons">The custom buttons.</param>
/// <param name="buttonsLayout">The buttons layout.</param>
/// <param name="autoSizeMode">The auto size mode.</param>
/// <param name="position">The position.</param>
/// <param name="showHelpButton">if set to <c>true</c> shows help button.</param>
/// <param name="helpNavigator">The help navigator.</param>
/// <param name="showDoNotShowAgainCheckBox">if set to <c>true</c> shows the do not show again check box.</param>
/// <param name="doNotShowAgainText">If not null, the value will replace the default text for the "Do not show again" checkbox.</param>
/// <param name="style">The style.</param>
/// <param name="autoClose">The auto close configuration.</param>
/// <param name="design">The design.</param>
/// <param name="fontParameters">The font parameters.</param>
/// <param name="titleStyle">The title style.</param>
/// <param name="titleIcon">The title icon.</param>
/// <param name="legacyButtons">The legacy buttons.</param>
/// <param name="legacyIcon">The legacy icon.</param>
/// <param name="legacyDefaultButton">The legacy default button.</param>
/// <param name="behavior">The behavior.</param>
/// <param name="callback">The callback.</param>
/// <param name="opacity">The opacity.</param>
/// <param name="parent">The parent form.</param>
/// <param name="order">The z-order</param>
/// <param name="sound">The sound</param>
internal InformationBoxForm(string text,
string title = "",
string helpFile = "",
string helpTopic = "",
InformationBoxInitialization initialization = InformationBoxInitialization.FromScopeAndParameters,
InformationBoxButtons buttons = InformationBoxButtons.OK,
InformationBoxIcon icon = InformationBoxIcon.None,
Icon customIcon = null,
InformationBoxDefaultButton defaultButton = InformationBoxDefaultButton.Button1,
string[] customButtons = null,
InformationBoxButtonsLayout buttonsLayout = InformationBoxButtonsLayout.GroupMiddle,
InformationBoxAutoSizeMode autoSizeMode = InformationBoxAutoSizeMode.None,
InformationBoxPosition position = InformationBoxPosition.CenterOnParent,
bool showHelpButton = false,
HelpNavigator helpNavigator = HelpNavigator.TableOfContents,
InformationBoxCheckBox showDoNotShowAgainCheckBox = 0,
string doNotShowAgainText = null,
InformationBoxStyle style = InformationBoxStyle.Standard,
AutoCloseParameters autoClose = null,
DesignParameters design = null,
FontParameters fontParameters = null,
InformationBoxTitleIconStyle titleStyle = InformationBoxTitleIconStyle.None,
InformationBoxTitleIcon titleIcon = null,
MessageBoxButtons? legacyButtons = null,
MessageBoxIcon? legacyIcon = null,
MessageBoxDefaultButton? legacyDefaultButton = null,
InformationBoxBehavior behavior = InformationBoxBehavior.Modal,
AsyncResultCallback callback = null,
InformationBoxOpacity opacity = InformationBoxOpacity.NoFade,
Form parent = null,
InformationBoxOrder order = InformationBoxOrder.Default,
InformationBoxSound sound = InformationBoxSound.Default)
{
this.InitializeComponent();
this.measureGraphics = CreateGraphics();
this.measureGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// Apply default font for message boxes
this.Font = SystemFonts.MessageBoxFont;
this.messageText.Font = SystemFonts.MessageBoxFont;
this.lblTitle.Font = SystemFonts.CaptionFont;
this.messageText.Text = text;
if (InformationBoxInitialization.FromParametersOnly == initialization)
{
this.LoadCurrentScope();
}
this.Text = title;
this.lblTitle.Text = title;
this.helpFile = helpFile;
this.helpTopic = helpTopic;
this.buttons = buttons;
this.icon = icon;
if (customIcon != null)
{
this.iconType = IconType.UserDefined;
this.customIcon = new Icon(customIcon, 48, 48);
}
this.defaultButton = defaultButton;
if (customButtons != null)
{
if (customButtons.Length > 0)
{
this.buttonUser1Text = customButtons[0];
}
if (customButtons.Length > 1)
{
this.buttonUser2Text = customButtons[1];
}
if (customButtons.Length > 2)
{
this.buttonUser3Text = customButtons[2];
}
}
this.buttonsLayout = buttonsLayout;
this.autoSizeMode = autoSizeMode;
this.position = position;
this.showHelpButton = showHelpButton;
this.helpNavigator = helpNavigator;
this.checkBox = showDoNotShowAgainCheckBox;
this.doNotShowAgainText = doNotShowAgainText;
this.style = style;
this.autoClose = autoClose;
this.design = design;
this.fontParameters = fontParameters;
this.titleStyle = titleStyle;
if (titleIcon != null)
{
this.titleIcon = titleIcon.Icon;
}
if (!(legacyButtons is null))
{
this.buttons = MessageBoxEnumConverter.Parse(legacyButtons.Value);
}
if (!(legacyIcon is null))
{
this.icon = MessageBoxEnumConverter.Parse(legacyIcon.Value);
}
if (!(legacyDefaultButton is null))
{
this.defaultButton = MessageBoxEnumConverter.Parse(legacyDefaultButton.Value);
}
this.behavior = behavior;
this.callback = callback;
this.opacity = opacity;
this.Parent = parent;
this.order = order;
this.sound = sound;
}
/// <summary>
/// Initializes a new instance of the <see cref="InformationBoxForm"/> class.
/// </summary>
/// <param name="text">The text of the box.</param>
/// <param name="parameters">The parameters.</param>
internal InformationBoxForm(string text, params object[] parameters)
: this(text)
{
this.activeForm = ActiveForm;
// Looks for a parameter of the type InformationBoxInitialization.
// If found and equal to InformationBoxInitialization.FromParametersOnly,
// skips the scope parameters.
bool loadScope = true;
foreach (object param in parameters)
{
if (param is InformationBoxInitialization)
{
InformationBoxInitialization value = (InformationBoxInitialization)param;
if (InformationBoxInitialization.FromParametersOnly == value)
{
loadScope = false;
}
}
}
if (loadScope)
{
this.LoadCurrentScope();
}
int stringCount = 0;
foreach (object parameter in parameters)
{
if (null == parameter)
{
continue;
}
// Simple string -> caption
// Or Help file if the string contains a file name
if (parameter is string)
{
if (stringCount == 0)
{
this.Text = (string)parameter;
this.lblTitle.Text = (string)parameter;
}
else if (stringCount == 1)
{
this.helpFile = (string)parameter;
}
else if (stringCount == 2)
{
this.helpTopic = (string)parameter;
}
else if (stringCount == 3)
{
this.doNotShowAgainText = (string)parameter;
}
stringCount++;
}
else if (parameter is InformationBoxButtons)
{
// Buttons
this.buttons = (InformationBoxButtons)parameter;
}
else if (parameter is InformationBoxIcon)
{
// Internal icon
this.icon = (InformationBoxIcon)parameter;
}
else if (parameter is Icon)
{
// User defined icon
this.iconType = IconType.UserDefined;
this.customIcon = new Icon((Icon)parameter, 48, 48);
}
else if (parameter is InformationBoxDefaultButton)
{
// Default button
this.defaultButton = (InformationBoxDefaultButton)parameter;
}
else if (parameter is string[])
{
// Custom buttons
string[] labels = (string[])parameter;
if (labels.Length > 0)
{
this.buttonUser1Text = labels[0];
}
if (labels.Length > 1)
{
this.buttonUser2Text = labels[1];
}
if (labels.Length > 2)
{
this.buttonUser3Text = labels[2];
}
}
else if (parameter is InformationBoxButtonsLayout)
{
// Buttons layout
this.buttonsLayout = (InformationBoxButtonsLayout)parameter;
}
else if (parameter is InformationBoxAutoSizeMode)
{
// Autosize mode
this.autoSizeMode = (InformationBoxAutoSizeMode)parameter;
}
else if (parameter is InformationBoxPosition)
{
// Position
this.position = (InformationBoxPosition)parameter;
}
else if (parameter is bool)
{
// Help button
this.showHelpButton = (bool)parameter;
}
else if (parameter is HelpNavigator)
{
// Help navigator
this.helpNavigator = (HelpNavigator)parameter;
}
else if (parameter is InformationBoxCheckBox)
{
// Do not show this dialog again ?
this.checkBox = (InformationBoxCheckBox)parameter;
}
else if (parameter is InformationBoxStyle)
{
// Visual style
this.style = (InformationBoxStyle)parameter;
}
else if (parameter is AutoCloseParameters)
{
// Auto-close parameters
this.autoClose = (AutoCloseParameters)parameter;
}
else if (parameter is DesignParameters)
{
// Design parameters
this.design = (DesignParameters)parameter;
}
else if (parameter is FontParameters)
{
// Font parameters
this.fontParameters = (FontParameters)parameter;
}
else if (parameter is Font)
{
// Direct font parameter - use for both message and title
this.fontParameters = new FontParameters((Font)parameter);
}
else if (parameter is InformationBoxTitleIconStyle)
{
// Title style
this.titleStyle = (InformationBoxTitleIconStyle)parameter;
}
else if (parameter is InformationBoxTitleIcon)
{
// Title icon
this.titleIcon = ((InformationBoxTitleIcon)parameter).Icon;
}
else if (parameter is MessageBoxButtons?)
{
// MessageBox buttons
this.buttons = MessageBoxEnumConverter.Parse((MessageBoxButtons)parameter);
}
else if (parameter is MessageBoxIcon?)
{
// MessageBox icon
this.icon = MessageBoxEnumConverter.Parse((MessageBoxIcon)parameter);
}
else if (parameter is MessageBoxDefaultButton?)
{
// MessageBox default button
this.defaultButton = MessageBoxEnumConverter.Parse((MessageBoxDefaultButton)parameter);
}
else if (parameter is InformationBoxBehavior)
{
// InformationBox behaviour
this.behavior = (InformationBoxBehavior)parameter;
}
else if (parameter is AsyncResultCallback)
{
// Callback for the result
this.callback = (AsyncResultCallback)parameter;
}
else if (parameter is InformationBoxOpacity)
{
// Opacity
this.opacity = (InformationBoxOpacity)parameter;
}
else if (parameter is Form)
{
// Form parent
this.Parent = (Form)Parent;
}
else if (parameter is InformationBoxOrder)
{
// z-order
this.order = (InformationBoxOrder)parameter;
}
else if (parameter is InformationBoxSound)
{
// Sound
this.sound = (InformationBoxSound)parameter;
}
}
}
#endregion Constructors
#region Show
/// <summary>
/// Shows this InformationBox.
/// </summary>
/// <returns>The result corresponding to the button clicked</returns>
internal new InformationBoxResult Show()
{
this.SetCheckBox();
this.SetButtons();
this.SetFont();
this.SetText();
this.SetIcon();
this.SetLayout();
this.SetFocus();
this.SetPosition();
this.SetWindowStyle();
this.SetAutoClose();
this.SetOpacity();
this.PlaySound();
this.SetOrder();
if (this.behavior == InformationBoxBehavior.Modal)
{
ShowDialog();
}
else
{
base.Show();
}
return this.result;
}
/// <summary>
/// Shows this InformationBox.
/// </summary>
/// <param name="state">The state of the checkbox.</param>
/// <returns>The result corresponding to the button clicked</returns>
internal InformationBoxResult Show(out CheckState state)
{
this.result = this.Show();
state = this.chbDoNotShow.CheckState;
return this.result;
}
#endregion Show
#region Sound
/// <summary>
/// Plays the sound associated with the icon type.
/// </summary>
private void PlaySound()
{
if (sound == InformationBoxSound.None)
{
return;
}
SystemSound soundToPlay;
if (this.iconType == IconType.UserDefined)
{
soundToPlay = SystemSounds.Beep;
}
else
{
switch (IconHelper.GetCategory(this.icon))
{
case InformationBoxMessageCategory.Asterisk:
soundToPlay = SystemSounds.Asterisk;
break;
case InformationBoxMessageCategory.Exclamation:
soundToPlay = SystemSounds.Exclamation;
break;
case InformationBoxMessageCategory.Hand:
soundToPlay = SystemSounds.Hand;
break;
case InformationBoxMessageCategory.Question:
soundToPlay = SystemSounds.Question;
break;
default:
soundToPlay = SystemSounds.Beep;
break;
}
}
if (null != soundToPlay)
{
soundToPlay.Play();
}
}
#endregion Sound
#region Box initialization
/// <summary>
/// Loads the current scope.
/// </summary>
private void LoadCurrentScope()
{
if (InformationBoxScope.Current == null)
{
return;
}
InformationBoxScopeParameters parameters = InformationBoxScope.Current.Parameters;
if (parameters.Icon.HasValue)
{
this.icon = parameters.Icon.Value;
}
if (parameters.CustomIcon != null)
{
this.iconType = IconType.UserDefined;
this.customIcon = parameters.CustomIcon;
}
if (parameters.Buttons.HasValue)
{
this.buttons = parameters.Buttons.Value;
}
if (parameters.DefaultButton.HasValue)
{
this.defaultButton = parameters.DefaultButton.Value;
}
if (parameters.Layout.HasValue)
{
this.buttonsLayout = parameters.Layout.Value;
}
if (parameters.AutoSizeMode.HasValue)
{
this.autoSizeMode = parameters.AutoSizeMode.Value;
}
if (parameters.Position.HasValue)
{
this.position = parameters.Position.Value;
}
if (parameters.CheckBox.HasValue)
{
this.checkBox = parameters.CheckBox.Value;
}
if (parameters.Style.HasValue)
{
this.style = parameters.Style.Value;
}
if (parameters.AutoClose != null)
{
this.autoClose = parameters.AutoClose;
}
if (parameters.Design != null)
{
this.design = parameters.Design;
}
if (parameters.Font != null)
{
this.fontParameters = parameters.Font;
}
if (parameters.TitleIconStyle.HasValue)
{
this.titleStyle = parameters.TitleIconStyle.Value;
}
if (parameters.TitleIcon != null)
{
this.titleIcon = parameters.TitleIcon;
}
if (parameters.Behavior.HasValue)
{
this.behavior = parameters.Behavior.Value;
}
if (parameters.Opacity.HasValue)
{
this.opacity = parameters.Opacity.Value;
}
if (parameters.Help.HasValue)
{
this.showHelpButton = parameters.Help.Value;
}
if (parameters.HelpNavigator.HasValue)
{
this.helpNavigator = parameters.HelpNavigator.Value;
}
if (parameters.Order.HasValue)
{
this.order = parameters.Order.Value;
}
if (parameters.Sound.HasValue)
{
this.sound = parameters.Sound.Value;
}
}
#region Auto close
/// <summary>
/// Sets the auto close parameters.
/// </summary>
private void SetAutoClose()
{
if (null == this.autoClose)
{
return;
}
this.tmrAutoClose.Interval = 1000;
this.tmrAutoClose.Tick += this.TmrAutoClose_Tick;
this.tmrAutoClose.Start();
}
#endregion Auto close
#region Opacity
/// <summary>
/// Sets the opacity.
/// </summary>
private void SetOpacity()
{
switch (this.opacity)
{
case InformationBoxOpacity.Faded10:
Opacity = 0.1;
break;
case InformationBoxOpacity.Faded20:
Opacity = 0.2;
break;
case InformationBoxOpacity.Faded30:
Opacity = 0.3;
break;
case InformationBoxOpacity.Faded40:
Opacity = 0.4;
break;
case InformationBoxOpacity.Faded50:
Opacity = 0.5;
break;
case InformationBoxOpacity.Faded60:
Opacity = 0.6;
break;
case InformationBoxOpacity.Faded70:
Opacity = 0.7;
break;
case InformationBoxOpacity.Faded80:
Opacity = 0.8;
break;
case InformationBoxOpacity.Faded90:
Opacity = 0.9;
break;
case InformationBoxOpacity.NoFade:
Opacity = 1.0;
break;
default:
break;
}
}
#endregion Opacity
#region Style
/// <summary>
/// Sets the window style.
/// </summary>
private void SetWindowStyle()
{
if (this.style == InformationBoxStyle.Modern)
{
Color barsBackColor = Color.Black;
Color formBackColor = Color.Silver;
if (null != this.design)
{
barsBackColor = this.design.BarsBackColor;
formBackColor = this.design.FormBackColor;
}
this.pnlForm.BackColor = formBackColor;
this.messageText.BackColor = formBackColor;
this.pnlButtons.BackColor = barsBackColor;
this.lblTitle.BackColor = barsBackColor;
FormBorderStyle = FormBorderStyle.None;
this.lblTitle.Visible = true;
foreach (Controls.Button button in this.pnlButtons.Controls)
{
button.BackColor = barsBackColor;
}
}
else if (this.style == InformationBoxStyle.Standard)
{
Color barsBackColor = SystemColors.Control;
Color formBackColor = SystemColors.Control;
if (null != this.design)
{
barsBackColor = this.design.BarsBackColor;
formBackColor = this.design.FormBackColor;
}
this.pnlButtons.BackColor = barsBackColor;
this.pnlForm.BackColor = formBackColor;
this.messageText.BackColor = formBackColor;
FormBorderStyle = FormBorderStyle.FixedDialog;
this.lblTitle.Visible = false;
this.pnlMain.Top -= this.lblTitle.Height;
this.pnlButtons.SideBorder = SideBorder.None;
}
}
#endregion Style
#region CheckBox
/// <summary>
/// Sets the check box.
/// </summary>
private void SetCheckBox()
{
this.chbDoNotShow.Text = this.doNotShowAgainText ?? Resources.LabelDoNotShow;
this.chbDoNotShow.Visible = ((this.checkBox & InformationBoxCheckBox.Show) == InformationBoxCheckBox.Show);
this.chbDoNotShow.Checked = ((this.checkBox & InformationBoxCheckBox.Checked) == InformationBoxCheckBox.Checked);
this.chbDoNotShow.TextAlign = ((this.checkBox & InformationBoxCheckBox.RightAligned) == InformationBoxCheckBox.RightAligned)
? ContentAlignment.BottomRight
: ContentAlignment.BottomLeft;
this.chbDoNotShow.CheckAlign = ((this.checkBox & InformationBoxCheckBox.RightAligned) == InformationBoxCheckBox.RightAligned)
? ContentAlignment.MiddleRight
: ContentAlignment.MiddleLeft;
}
#endregion CheckBox
#region Position
/// <summary>
/// Sets the position.
/// </summary>
private void SetPosition()
{
if (this.position == InformationBoxPosition.CenterOnScreen)
{
StartPosition = FormStartPosition.CenterScreen;
CenterToScreen();
}
else
{
if (this.Parent != null && ((Form)this.Parent).IsMdiChild)
{
StartPosition = FormStartPosition.CenterScreen;
}
else
{
StartPosition = FormStartPosition.CenterParent;
}
CenterToParent();
}
}
#endregion Position
#region Focus
/// <summary>
/// Sets the focus.
/// </summary>
private void SetFocus()
{
if (this.defaultButton == InformationBoxDefaultButton.Button1 && this.pnlButtons.Controls.Count > 0)
{
this.pnlButtons.Controls[0].Select();
}
if (this.defaultButton == InformationBoxDefaultButton.Button2 && this.pnlButtons.Controls.Count > 1)
{
this.pnlButtons.Controls[1].Select();
}
if (this.defaultButton == InformationBoxDefaultButton.Button3 && this.pnlButtons.Controls.Count > 2)
{
this.pnlButtons.Controls[2].Select();
}
}
#endregion Focus
#region Layout
/// <summary>
/// Sets the layout.