-
Notifications
You must be signed in to change notification settings - Fork 0
/
WizardStepBase.cs
539 lines (456 loc) · 15 KB
/
WizardStepBase.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
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
/*
© 2005, 2011 MAY-MART. All rights reserved.
The code is originally based on TSWizard library (http://www.codeproject.com/KB/dialog/tswizard.aspx).
*/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace MayMart.WinFormsWizard
{
[DefaultEvent("ShowStep")]
public partial class WizardStepBase : UserControl
{
private static readonly object _eventResetStep = new object();
private static readonly object _eventShowStep = new object();
private static readonly object _eventFormClosing = new object();
private static readonly object _eventLogoChanged = new object();
private static readonly object _eventNextStepChanged = new object();
private static readonly object _eventStepLayoutChanged = new object();
private static readonly object _eventPreviousStepChanged = new object();
private static readonly object _eventCanBeCancelledChanged = new object();
private static readonly object _eventSideBarImageChanged = new object();
private static readonly object _eventStepDescriptionChanged = new object();
private static readonly object _eventStepTitleChanged = new object();
private static readonly object _eventValidateStep = new object();
private Image _imageStepLogo;
private Image _sideBarImage;
private StepLayout _stepLayout;
private string _stepTitle;
private string _stepDescription;
private string _nextStepKey;
private bool _nextStepEnabled;
private bool _canBeCancelled = true;
[Browsable(false)]
public WizardBase Wizard { get; set; }
[Browsable(true)]
[Category("Wizard Step")]
[Description("Gets or sets the title text that will be displayed in the white portion above the step.")]
[DefaultValue("Step Title")]
public string StepTitle
{
get
{
return _stepTitle;
}
set
{
_stepTitle = value;
OnStepTitleChanged(EventArgs.Empty);
}
}
[Browsable(true)]
[Category("Wizard Step")]
[Description("Gets or sets the description text that will be displayed in the white portion above the step.")]
public string StepDescription
{
get
{
return _stepDescription;
}
set
{
_stepDescription = value;
OnStepDescriptionChanged(EventArgs.Empty);
}
}
[Browsable(true)]
[Category("Wizard Step")]
[Description("Gets or sets the custom logo for this step.")]
[DefaultValue(null)]
public Image StepLogo
{
get
{
return _imageStepLogo;
}
set
{
_imageStepLogo = value;
OnLogoChanged(EventArgs.Empty);
}
}
[Browsable(true)]
[Category("Wizard Step")]
[Description("Gets or sets the image to display in the sidebar for exterior pages.")]
[DefaultValue(null)]
public Image SideBarImage
{
get
{
return _sideBarImage;
}
set
{
_sideBarImage = value;
OnSideBarImageChanged(EventArgs.Empty);
}
}
[Browsable(false)]
public NextStepMode NextStepMode { get; private set; }
[Browsable(false)]
public string NextStepKey
{
get
{
return NextStepMode == NextStepMode.Next ? _nextStepKey : null;
}
}
[Browsable(false)]
public bool NextStepEnabled
{
get
{
return _nextStepEnabled && (NextStepMode == NextStepMode.Finish || !string.IsNullOrEmpty(_nextStepKey));
}
}
[Browsable(false)]
public string PreviousStepKey { get; private set; }
[Browsable(true)]
[Category("Wizard Step")]
[Description("Gets or sets whether this step can be cancelled/closed by user.")]
[DefaultValue(true)]
public bool CanBeCancelled
{
get
{
return _canBeCancelled;
}
set
{
_canBeCancelled = value;
OnCanBeCancelledChanged(EventArgs.Empty);
}
}
[Browsable(false)]
public StepLayout StepLayout
{
get
{
return _stepLayout;
}
set
{
_stepLayout = value;
OnStepLayoutChanged(EventArgs.Empty);
}
}
[Description("Fired when closing form"), Category("Wizard Step"), Browsable(true)]
public event FormClosingEventHandler FormClosing
{
add
{
Events.AddHandler(_eventFormClosing, value);
}
remove
{
Events.RemoveHandler(_eventFormClosing, value);
}
}
[Browsable(true), Category("Wizard Step"), Description("Fired when the StepLogo property has changed")]
public event EventHandler LogoChanged
{
add
{
Events.AddHandler(_eventLogoChanged, value);
}
remove
{
Events.RemoveHandler(_eventLogoChanged, value);
}
}
[Browsable(true)]
[Category("Wizard Step")]
[Description("Fired when the NextStep property has changed.")]
public event EventHandler NextStepChanged
{
add
{
Events.AddHandler(_eventNextStepChanged, value);
}
remove
{
Events.RemoveHandler(_eventNextStepChanged, value);
}
}
[Browsable(true)]
[Category("Wizard Step")]
[Description("Fired when the PreviousStep property has changed.")]
public event EventHandler PreviousStepChanged
{
add
{
Events.AddHandler(_eventPreviousStepChanged, value);
}
remove
{
Events.RemoveHandler(_eventPreviousStepChanged, value);
}
}
[Browsable(true)]
[Category("Wizard Step")]
[Description("Fired when the CanBeCancelled property has changed.")]
public event EventHandler CanBeCancelledChanged
{
add
{
Events.AddHandler(_eventCanBeCancelledChanged, value);
}
remove
{
Events.RemoveHandler(_eventCanBeCancelledChanged, value);
}
}
[Browsable(true), Category("Wizard"), Description("Fired when the StepLayout property has changed")]
public event EventHandler PageLayoutChanged
{
add
{
Events.AddHandler(_eventStepLayoutChanged, value);
}
remove
{
Events.RemoveHandler(_eventStepLayoutChanged, value);
}
}
[Browsable(true), Category("Wizard"), Description("Fired when the step needs to reset itself, this is fired when the wizard is reset and when the wizard is first shown")]
public event EventHandler ResetStep
{
add
{
Events.AddHandler(_eventResetStep, value);
}
remove
{
Events.RemoveHandler(_eventResetStep, value);
}
}
[Category("Wizard"), Browsable(true), Description("Fired every time the step is shown in the wizard")]
public event ShowStepEventHandler ShowStep
{
add
{
Events.AddHandler(_eventShowStep, value);
}
remove
{
Events.RemoveHandler(_eventShowStep, value);
}
}
[Category("Wizard Step"), Browsable(true), Description("Fired when the SideBarImage property has changed")]
public event EventHandler SideBarImageChanged
{
add
{
Events.AddHandler(_eventSideBarImageChanged, value);
}
remove
{
Events.RemoveHandler(_eventSideBarImageChanged, value);
}
}
[Category("Wizard Step"), Browsable(true), Description("Fired when the StepTitle property has changed")]
public event EventHandler StepTitleChanged
{
add
{
Events.AddHandler(_eventStepTitleChanged, value);
}
remove
{
Events.RemoveHandler(_eventStepTitleChanged, value);
}
}
[Category("Wizard Step"), Description("Fired when the StepDescription property has changed"), Browsable(true)]
public event EventHandler StepDescriptionChanged
{
add
{
Events.AddHandler(_eventStepDescriptionChanged, value);
}
remove
{
Events.RemoveHandler(_eventStepDescriptionChanged, value);
}
}
[Browsable(true), Category("Wizard Step"), Description("Fired when moving to the next step")]
public event CancelEventHandler ValidateStep
{
add
{
Events.AddHandler(_eventValidateStep, value);
}
remove
{
Events.RemoveHandler(_eventValidateStep, value);
}
}
public WizardStepBase()
{
InitializeComponent();
}
public T GetWizard<T>()
where T : WizardBase
{
return (T)Wizard;
}
public void SetNextStep<T>(string name = null)
where T : WizardStepBase
{
NextStepMode = NextStepMode.Next;
_nextStepKey = WizardBase.GetStepKey<T>(name);
_nextStepEnabled = true;
OnNextStepChanged(EventArgs.Empty);
}
public void DisableNextStep()
{
NextStepMode = NextStepMode.Next;
_nextStepEnabled = false;
OnNextStepChanged(EventArgs.Empty);
}
public void SetFinishStep()
{
NextStepMode = NextStepMode.Finish;
_nextStepEnabled = true;
OnNextStepChanged(EventArgs.Empty);
}
public void DisableFinishStep()
{
NextStepMode = NextStepMode.Finish;
_nextStepEnabled = false;
OnNextStepChanged(EventArgs.Empty);
}
public void SetPreviousStep<T>(string name = null)
where T : WizardStepBase
{
PreviousStepKey = WizardBase.GetStepKey<T>(name);
OnPreviousStepChanged(EventArgs.Empty);
}
public void DisablePreviousStep()
{
PreviousStepKey = null;
OnPreviousStepChanged(EventArgs.Empty);
}
internal void FireResetStepEvent()
{
OnResetStep(EventArgs.Empty);
}
internal void FireShowEvent(ShowStepEventArgs e)
{
OnShowStep(e);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal virtual void OnFormClosing(FormClosingEventArgs e)
{
FormClosingEventHandler handler = (FormClosingEventHandler) Events[_eventFormClosing];
if (handler != null)
handler(this, e);
}
protected virtual void OnLogoChanged(EventArgs e)
{
EventHandler handler = (EventHandler) Events[_eventLogoChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnNextStepChanged(EventArgs e)
{
EventHandler handler = (EventHandler) Events[_eventNextStepChanged];
if (handler != null)
handler(this, e);
}
protected void OnCanBeCancelledChanged(EventArgs e)
{
EventHandler handler = (EventHandler)Events[_eventCanBeCancelledChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnStepLayoutChanged(EventArgs e)
{
EventHandler handler = (EventHandler) Events[_eventStepLayoutChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnPreviousStepChanged(EventArgs e)
{
EventHandler handler = (EventHandler) Events[_eventPreviousStepChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnResetStep(EventArgs e)
{
EventHandler handler = (EventHandler) Events[_eventResetStep];
if (handler != null)
handler(this, e);
}
protected virtual void OnShowStep(ShowStepEventArgs e)
{
ShowStepEventHandler handler = (ShowStepEventHandler) Events[_eventShowStep];
if (handler != null)
handler(this, e);
}
protected virtual void OnStepTitleChanged(EventArgs e)
{
EventHandler handler = (EventHandler)Events[_eventStepTitleChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnStepDescriptionChanged(EventArgs e)
{
EventHandler handler = (EventHandler)Events[_eventStepDescriptionChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnSideBarImageChanged(EventArgs e)
{
EventHandler handler = (EventHandler) Events[_eventSideBarImageChanged];
if (handler != null)
handler(this, e);
}
protected virtual void OnValidateStep(CancelEventArgs e)
{
CancelEventHandler handler = (CancelEventHandler) Events[_eventValidateStep];
if (handler != null)
handler(this, e);
}
internal void NextClicked()
{
OnNext();
}
internal void FinishClicked()
{
OnFinish();
}
internal void BackClicked()
{
OnBack();
}
protected virtual void OnNext()
{
CancelEventArgs e = new CancelEventArgs();
OnValidateStep(e);
if (!e.Cancel)
Wizard.GotoNext();
}
protected virtual void OnFinish()
{
CancelEventArgs e = new CancelEventArgs();
OnValidateStep(e);
if (!e.Cancel)
Wizard.Finish();
}
protected virtual void OnBack()
{
Wizard.GotoBack();
}
}
}