C#设计的一个向导程序(Wizard)框架
在现实的软件中,经常可以看到一些向导(Wizard)的存在,如何给自己的应用程序实现一个向导呢?
下面给出一个使用面向对象的思想设计出来的应用程序向导框架,虽然很简单,但希望能给人帮助。
 其中有三个比较关键的类,一个是向导窗体要收集的信息封装成的类Information,一个是所有向导窗体都要继承的窗体基类frmBase,还有一个就是最关键的类,向导控制类WizardController。
有了基类frmBase,设计一个子类窗体非常简单,只需从frmBase类中派生一个新窗体,设计完用户界面之后重写其UpdateInfo()方法即可。
所有代码(VS2003版)如下,通俗易懂,不再做说明:
Information类:
 1 using System;
using System;
2
3 namespace Wizard
namespace Wizard
4 {
{
5 /// <summary>
 /// <summary>
6 /// Information 的摘要说明。
 /// Information 的摘要说明。
7 /// </summary>
 /// </summary>
8 public class Information
 public class Information
9 {
 {
10 public Information()
  public Information()
11 {
  {
12 //
   //
13 // TODO: 在此处添加构造函数逻辑
   // TODO: 在此处添加构造函数逻辑
14 //
   //
15 }
  }
16
17 //姓名
  //姓名
18 public string Name = "";
  public string Name = "";
19 //性别
  //性别
20 public bool IsMale = true;
  public bool IsMale = true;
21 //学历
  //学历
22 public string EduBackground = "";
  public string EduBackground = "";
23 //编程语言
  //编程语言
24 public string ProgrameLanguage = "";
  public string ProgrameLanguage = "";
25 }
 }
26 }
}
 using System;
using System;2

3
 namespace Wizard
namespace Wizard4
 {
{5
 /// <summary>
 /// <summary>6
 /// Information 的摘要说明。
 /// Information 的摘要说明。7
 /// </summary>
 /// </summary>8
 public class Information
 public class Information9
 {
 {10
 public Information()
  public Information()11
 {
  {12
 //
   //13
 // TODO: 在此处添加构造函数逻辑
   // TODO: 在此处添加构造函数逻辑14
 //
   //15
 }
  }16

17
 //姓名
  //姓名18
 public string Name = "";
  public string Name = "";19
 //性别
  //性别20
 public bool IsMale = true;
  public bool IsMale = true;21
 //学历
  //学历22
 public string EduBackground = "";
  public string EduBackground = "";23
 //编程语言
  //编程语言24
 public string ProgrameLanguage = "";
  public string ProgrameLanguage = "";25
 }
 }26
 }
}frmBase类:
  1 using System;
using System;
2 using System.Drawing;
using System.Drawing;
3 using System.Collections;
using System.Collections;
4 using System.ComponentModel;
using System.ComponentModel;
5 using System.Windows.Forms;
using System.Windows.Forms;
6
7 namespace Wizard
namespace Wizard
8 {
{
9 /// <summary>
 /// <summary>
10 /// frmBase 的摘要说明。
 /// frmBase 的摘要说明。
11 /// </summary>
 /// </summary>
12 public class frmBase : System.Windows.Forms.Form
 public class frmBase : System.Windows.Forms.Form
13 {
 {
14 private System.Windows.Forms.Panel panel1;
  private System.Windows.Forms.Panel panel1;
15 private System.Windows.Forms.Button btnGoPrev;
  private System.Windows.Forms.Button btnGoPrev;
16 private System.Windows.Forms.Button btnGoNext;
  private System.Windows.Forms.Button btnGoNext;
17 private System.Windows.Forms.Button btnOver;
  private System.Windows.Forms.Button btnOver;
18 private System.Windows.Forms.Button btnCancel;
  private System.Windows.Forms.Button btnCancel;
19 private System.Windows.Forms.Button btnHelp;
  private System.Windows.Forms.Button btnHelp;
20 /// <summary>
  /// <summary>
21 /// 必需的设计器变量。
  /// 必需的设计器变量。
22 /// </summary>
  /// </summary>
23 private System.ComponentModel.Container components = null;
  private System.ComponentModel.Container components = null;
24
25 public frmBase()
  public frmBase()
26 {
  {
27 //
   //
28 // Windows 窗体设计器支持所必需的
   // Windows 窗体设计器支持所必需的
29 //
   //
30 InitializeComponent();
   InitializeComponent();
31
32 //
   //
33 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
34 //
   //
35 }
  }
36
37 /// <summary>
  /// <summary>
38 /// 清理所有正在使用的资源。
  /// 清理所有正在使用的资源。
39 /// </summary>
  /// </summary>
40 protected override void Dispose( bool disposing )
  protected override void Dispose( bool disposing )
41 {
  {
42 if( disposing )
   if( disposing )
43 {
   {
44 if(components != null)
    if(components != null)
45 {
    {
46 components.Dispose();
     components.Dispose();
47 }
    }
48 }
   }
49 base.Dispose( disposing );
   base.Dispose( disposing );
50 }
  }
51
52 Windows 窗体设计器生成的代码
  Windows 窗体设计器生成的代码
144
145 public WizardController controller = null;
  public WizardController controller = null;
146
147 public void DisableButton()
  public void DisableButton()
148 {
  {
149 if(this.controller == null)
   if(this.controller == null)
150 return;
    return;
151 if(this.controller.IsFirstForm)
   if(this.controller.IsFirstForm)
152 {
   {
153 this.btnGoPrev.Enabled = false;
    this.btnGoPrev.Enabled = false;
154 }
   }
155 else
   else
156 {
   {
157 this.btnGoPrev.Enabled = true;
    this.btnGoPrev.Enabled = true;
158 }
   }
159 if(this.controller.IsLastForm)
   if(this.controller.IsLastForm)
160 {
   {
161 this.btnGoNext.Enabled = false;
    this.btnGoNext.Enabled = false;
162 }
   }
163 else
   else
164 {
   {
165 this.btnGoNext.Enabled = true;
    this.btnGoNext.Enabled = true;
166 }
   }
167 }
  }
168 protected virtual void UpdateInfo()
  protected virtual void UpdateInfo()
169 {
  {
170 
  
171 }
  }
172 protected virtual void GoNext()
  protected virtual void GoNext()
173 {
  {
174 UpdateInfo();
   UpdateInfo();
175 controller.GoNext();
   controller.GoNext();
176 }
  }
177 protected virtual void GoPrev()
  protected virtual void GoPrev()
178 {
  {
179 UpdateInfo();
   UpdateInfo();
180 controller.GoPrev();
   controller.GoPrev();
181 }
  }
182 protected virtual void Finish()
  protected virtual void Finish()
183 {
  {
184 UpdateInfo();
   UpdateInfo();
185 controller.FinishWizard();
   controller.FinishWizard();
186 this.Visible = false;
   this.Visible = false;
187 }
  }
188 protected virtual void Cancel()
  protected virtual void Cancel()
189 {
  {
190 this.controller.info = null;
   this.controller.info = null;
191 this.Close();
   this.Close();
192 }
  }
193
194 private void btnGoPrev_Click(object sender, System.EventArgs e)
  private void btnGoPrev_Click(object sender, System.EventArgs e)
195 {
  {
196 GoPrev();
   GoPrev();
197 }
  }
198
199 private void btnGoNext_Click(object sender, System.EventArgs e)
  private void btnGoNext_Click(object sender, System.EventArgs e)
200 {
  {
201 GoNext();
   GoNext();
202 }
  }
203
204 private void btnOver_Click(object sender, System.EventArgs e)
  private void btnOver_Click(object sender, System.EventArgs e)
205 {
  {
206 Finish();
   Finish();
207 }
  }
208
209 private void btnCancel_Click(object sender, System.EventArgs e)
  private void btnCancel_Click(object sender, System.EventArgs e)
210 {
  {
211 Cancel();
   Cancel();
212 }
  }
213 }
 }
214 }
}
 using System;
using System;2
 using System.Drawing;
using System.Drawing;3
 using System.Collections;
using System.Collections;4
 using System.ComponentModel;
using System.ComponentModel;5
 using System.Windows.Forms;
using System.Windows.Forms;6

7
 namespace Wizard
namespace Wizard8
 {
{9
 /// <summary>
 /// <summary>10
 /// frmBase 的摘要说明。
 /// frmBase 的摘要说明。11
 /// </summary>
 /// </summary>12
 public class frmBase : System.Windows.Forms.Form
 public class frmBase : System.Windows.Forms.Form13
 {
 {14
 private System.Windows.Forms.Panel panel1;
  private System.Windows.Forms.Panel panel1;15
 private System.Windows.Forms.Button btnGoPrev;
  private System.Windows.Forms.Button btnGoPrev;16
 private System.Windows.Forms.Button btnGoNext;
  private System.Windows.Forms.Button btnGoNext;17
 private System.Windows.Forms.Button btnOver;
  private System.Windows.Forms.Button btnOver;18
 private System.Windows.Forms.Button btnCancel;
  private System.Windows.Forms.Button btnCancel;19
 private System.Windows.Forms.Button btnHelp;
  private System.Windows.Forms.Button btnHelp;20
 /// <summary>
  /// <summary>21
 /// 必需的设计器变量。
  /// 必需的设计器变量。22
 /// </summary>
  /// </summary>23
 private System.ComponentModel.Container components = null;
  private System.ComponentModel.Container components = null;24

25
 public frmBase()
  public frmBase()26
 {
  {27
 //
   //28
 // Windows 窗体设计器支持所必需的
   // Windows 窗体设计器支持所必需的29
 //
   //30
 InitializeComponent();
   InitializeComponent();31

32
 //
   //33
 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码34
 //
   //35
 }
  }36

37
 /// <summary>
  /// <summary>38
 /// 清理所有正在使用的资源。
  /// 清理所有正在使用的资源。39
 /// </summary>
  /// </summary>40
 protected override void Dispose( bool disposing )
  protected override void Dispose( bool disposing )41
 {
  {42
 if( disposing )
   if( disposing )43
 {
   {44
 if(components != null)
    if(components != null)45
 {
    {46
 components.Dispose();
     components.Dispose();47
 }
    }48
 }
   }49
 base.Dispose( disposing );
   base.Dispose( disposing );50
 }
  }51

52
 Windows 窗体设计器生成的代码
  Windows 窗体设计器生成的代码144

145
 public WizardController controller = null;
  public WizardController controller = null;146

147
 public void DisableButton()
  public void DisableButton()148
 {
  {149
 if(this.controller == null)
   if(this.controller == null)150
 return;
    return;151
 if(this.controller.IsFirstForm)
   if(this.controller.IsFirstForm)152
 {
   {153
 this.btnGoPrev.Enabled = false;
    this.btnGoPrev.Enabled = false;154
 }
   }155
 else
   else156
 {
   {157
 this.btnGoPrev.Enabled = true;
    this.btnGoPrev.Enabled = true;158
 }
   }159
 if(this.controller.IsLastForm)
   if(this.controller.IsLastForm)160
 {
   {161
 this.btnGoNext.Enabled = false;
    this.btnGoNext.Enabled = false;162
 }
   }163
 else
   else164
 {
   {165
 this.btnGoNext.Enabled = true;
    this.btnGoNext.Enabled = true;166
 }
   }167
 }
  }168
 protected virtual void UpdateInfo()
  protected virtual void UpdateInfo()169
 {
  {170
 
  171
 }
  }172
 protected virtual void GoNext()
  protected virtual void GoNext()173
 {
  {174
 UpdateInfo();
   UpdateInfo();175
 controller.GoNext();
   controller.GoNext();176
 }
  }177
 protected virtual void GoPrev()
  protected virtual void GoPrev()178
 {
  {179
 UpdateInfo();
   UpdateInfo();180
 controller.GoPrev();
   controller.GoPrev();181
 }
  }182
 protected virtual void Finish()
  protected virtual void Finish()183
 {
  {184
 UpdateInfo();
   UpdateInfo();185
 controller.FinishWizard();
   controller.FinishWizard();186
 this.Visible = false;
   this.Visible = false;187
 }
  }188
 protected virtual void Cancel()
  protected virtual void Cancel()189
 {
  {190
 this.controller.info = null;
   this.controller.info = null;191
 this.Close();
   this.Close();192
 }
  }193

194
 private void btnGoPrev_Click(object sender, System.EventArgs e)
  private void btnGoPrev_Click(object sender, System.EventArgs e)195
 {
  {196
 GoPrev();
   GoPrev();197
 }
  }198

199
 private void btnGoNext_Click(object sender, System.EventArgs e)
  private void btnGoNext_Click(object sender, System.EventArgs e)200
 {
  {201
 GoNext();
   GoNext();202
 }
  }203

204
 private void btnOver_Click(object sender, System.EventArgs e)
  private void btnOver_Click(object sender, System.EventArgs e)205
 {
  {206
 Finish();
   Finish();207
 }
  }208

209
 private void btnCancel_Click(object sender, System.EventArgs e)
  private void btnCancel_Click(object sender, System.EventArgs e)210
 {
  {211
 Cancel();
   Cancel();212
 }
  }213
 }
 }214
 }
}向导控制器WizardController类:
 1 using System;
using System;
2 using System.Collections;
using System.Collections;
3
4 namespace Wizard
namespace Wizard
5 {
{
6 /// <summary>
 /// <summary>
7 /// WizardController 的摘要说明。
 /// WizardController 的摘要说明。
8 /// </summary>
 /// </summary>
9 public class WizardController
 public class WizardController
10 {
 {
11 public WizardController()
  public WizardController()
12 {
  {
13 //
   //
14 // TODO: 在此处添加构造函数逻辑
   // TODO: 在此处添加构造函数逻辑
15 //
   //
16 WizardForms.Add(new frmStep1());
   WizardForms.Add(new frmStep1());
17 WizardForms.Add(new frmStep2());
   WizardForms.Add(new frmStep2());
18 foreach(frmBase frm in WizardForms)
   foreach(frmBase frm in WizardForms)
19 {
   {
20 frm.controller = this;
    frm.controller = this;
21 frm.DisableButton();
    frm.DisableButton();
22 }
   }
23 }
  }
24 private ArrayList WizardForms = new ArrayList();
  private ArrayList WizardForms = new ArrayList();
25 public Information info = new Information();
  public Information info = new Information();
26 private int curIndex = 0;
  private int curIndex = 0;
27
28 public bool IsFirstForm
  public bool IsFirstForm
29 {
  {
30 get{ return curIndex == 0;}
   get{ return curIndex == 0;}   
31 }
  }
32 public bool IsLastForm
  public bool IsLastForm
33 {
  {
34 get{return curIndex == this.WizardForms.Count - 1;}
   get{return curIndex == this.WizardForms.Count - 1;} 
35 }
  }
36 public void GoNext()
  public void GoNext()
37 {
  {
38 if(curIndex+1 < WizardForms.Count)
   if(curIndex+1 < WizardForms.Count)
39 {
   {
40 ((frmBase)WizardForms[curIndex]).Visible = false;
    ((frmBase)WizardForms[curIndex]).Visible = false;
41 curIndex++;
    curIndex++;
42 }
   }
43 else
   else
44 {
   {
45 return;
    return;
46 }
   }
47 ((frmBase)WizardForms[curIndex]).Show();
   ((frmBase)WizardForms[curIndex]).Show();
48 ((frmBase)WizardForms[curIndex]).DisableButton();
   ((frmBase)WizardForms[curIndex]).DisableButton();
49 }
  }
50 public void GoPrev()
  public void GoPrev()
51 {
  {
52 if(curIndex-1 >= 0)
   if(curIndex-1 >= 0)
53 {
   {
54 ((frmBase)WizardForms[curIndex]).Visible = false;
    ((frmBase)WizardForms[curIndex]).Visible = false;
55 curIndex--;
    curIndex--;
56 }
   }
57 else
   else
58 {
   {
59 return;
    return;
60 }
   }
61 ((frmBase)WizardForms[curIndex]).Show();
   ((frmBase)WizardForms[curIndex]).Show();
62 ((frmBase)WizardForms[curIndex]).DisableButton();
   ((frmBase)WizardForms[curIndex]).DisableButton();
63 }
  }
64 public void BeginWizard()
  public void BeginWizard()
65 {
  {
66 ((frmBase)WizardForms[0]).Show();
   ((frmBase)WizardForms[0]).Show();
67 ((frmBase)WizardForms[curIndex]).DisableButton();
   ((frmBase)WizardForms[curIndex]).DisableButton();
68 }
  }
69 public void FinishWizard()
  public void FinishWizard()
70 {
  {
71 curIndex = 0;
   curIndex = 0;
72 Dispose();
   Dispose();
73 }
  }
74
75 private void Dispose()
  private void Dispose()
76 {
  {
77 foreach(frmBase frm in WizardForms)
   foreach(frmBase frm in WizardForms)
78 {
   {
79 frm.Close();
    frm.Close();
80 }
   }
81 }
  }
82 }
 }
83 }
}
 using System;
using System;2
 using System.Collections;
using System.Collections;3

4
 namespace Wizard
namespace Wizard5
 {
{6
 /// <summary>
 /// <summary>7
 /// WizardController 的摘要说明。
 /// WizardController 的摘要说明。8
 /// </summary>
 /// </summary>9
 public class WizardController
 public class WizardController10
 {
 {11
 public WizardController()
  public WizardController()12
 {
  {13
 //
   //14
 // TODO: 在此处添加构造函数逻辑
   // TODO: 在此处添加构造函数逻辑15
 //
   //16
 WizardForms.Add(new frmStep1());
   WizardForms.Add(new frmStep1());17
 WizardForms.Add(new frmStep2());
   WizardForms.Add(new frmStep2());18
 foreach(frmBase frm in WizardForms)
   foreach(frmBase frm in WizardForms)19
 {
   {20
 frm.controller = this;
    frm.controller = this;21
 frm.DisableButton();
    frm.DisableButton();22
 }
   }23
 }
  }24
 private ArrayList WizardForms = new ArrayList();
  private ArrayList WizardForms = new ArrayList();25
 public Information info = new Information();
  public Information info = new Information();26
 private int curIndex = 0;
  private int curIndex = 0;27

28
 public bool IsFirstForm
  public bool IsFirstForm29
 {
  {30
 get{ return curIndex == 0;}
   get{ return curIndex == 0;}   31
 }
  }32
 public bool IsLastForm
  public bool IsLastForm33
 {
  {34
 get{return curIndex == this.WizardForms.Count - 1;}
   get{return curIndex == this.WizardForms.Count - 1;} 35
 }
  }36
 public void GoNext()
  public void GoNext()37
 {
  {38
 if(curIndex+1 < WizardForms.Count)
   if(curIndex+1 < WizardForms.Count)39
 {
   {40
 ((frmBase)WizardForms[curIndex]).Visible = false;
    ((frmBase)WizardForms[curIndex]).Visible = false;41
 curIndex++;
    curIndex++;42
 }
   }43
 else
   else44
 {
   {45
 return;
    return;46
 }
   }47
 ((frmBase)WizardForms[curIndex]).Show();
   ((frmBase)WizardForms[curIndex]).Show();48
 ((frmBase)WizardForms[curIndex]).DisableButton();
   ((frmBase)WizardForms[curIndex]).DisableButton();49
 }
  }50
 public void GoPrev()
  public void GoPrev()51
 {
  {52
 if(curIndex-1 >= 0)
   if(curIndex-1 >= 0)53
 {
   {54
 ((frmBase)WizardForms[curIndex]).Visible = false;
    ((frmBase)WizardForms[curIndex]).Visible = false;55
 curIndex--;
    curIndex--;56
 }
   }57
 else
   else58
 {
   {59
 return;
    return;60
 }
   }61
 ((frmBase)WizardForms[curIndex]).Show();
   ((frmBase)WizardForms[curIndex]).Show();62
 ((frmBase)WizardForms[curIndex]).DisableButton();
   ((frmBase)WizardForms[curIndex]).DisableButton();63
 }
  }64
 public void BeginWizard()
  public void BeginWizard()65
 {
  {66
 ((frmBase)WizardForms[0]).Show();
   ((frmBase)WizardForms[0]).Show();67
 ((frmBase)WizardForms[curIndex]).DisableButton();
   ((frmBase)WizardForms[curIndex]).DisableButton();68
 }
  }69
 public void FinishWizard()
  public void FinishWizard()70
 {
  {71
 curIndex = 0;
   curIndex = 0;72
 Dispose();
   Dispose();73
 }
  }74

75
 private void Dispose()
  private void Dispose()76
 {
  {77
 foreach(frmBase frm in WizardForms)
   foreach(frmBase frm in WizardForms)78
 {
   {79
 frm.Close();
    frm.Close();80
 }
   }81
 }
  }82
 }
 }83
 }
}第一个子窗体:
  1 using System;
using System;
2 using System.Collections;
using System.Collections;
3 using System.ComponentModel;
using System.ComponentModel;
4 using System.Drawing;
using System.Drawing;
5 using System.Windows.Forms;
using System.Windows.Forms;
6
7 namespace Wizard
namespace Wizard
8 {
{
9 public class frmStep1 : Wizard.frmBase
 public class frmStep1 : Wizard.frmBase
10 {
 {
11 private System.Windows.Forms.TextBox txtName;
  private System.Windows.Forms.TextBox txtName;
12 private System.Windows.Forms.RadioButton rdoMale;
  private System.Windows.Forms.RadioButton rdoMale;
13 private System.Windows.Forms.RadioButton radioButton1;
  private System.Windows.Forms.RadioButton radioButton1;
14 private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label1;
15 private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label2;
16 private System.ComponentModel.IContainer components = null;
  private System.ComponentModel.IContainer components = null;
17
18 public frmStep1()
  public frmStep1()
19 {
  {
20 // 该调用是 Windows 窗体设计器所必需的。
   // 该调用是 Windows 窗体设计器所必需的。
21 InitializeComponent();
   InitializeComponent();
22
23 // TODO: 在 InitializeComponent 调用后添加任何初始化
   // TODO: 在 InitializeComponent 调用后添加任何初始化
24 }
  }
25
26 /// <summary>
  /// <summary>
27 /// 清理所有正在使用的资源。
  /// 清理所有正在使用的资源。
28 /// </summary>
  /// </summary>
29 protected override void Dispose( bool disposing )
  protected override void Dispose( bool disposing )
30 {
  {
31 if( disposing )
   if( disposing )
32 {
   {
33 if (components != null)
    if (components != null) 
34 {
    {
35 components.Dispose();
     components.Dispose();
36 }
    }
37 }
   }
38 base.Dispose( disposing );
   base.Dispose( disposing );
39 }
  }
40
41 设计器生成的代码
  设计器生成的代码
114
115 protected override void UpdateInfo()
  protected override void UpdateInfo()
116 {
  {
117 this.controller.info.Name = txtName.Text.Trim();
   this.controller.info.Name = txtName.Text.Trim();
118 this.controller.info.IsMale = rdoMale.Checked;
   this.controller.info.IsMale = rdoMale.Checked;
119 }
  }
120
121 }
 }
122 }
}
 using System;
using System;2
 using System.Collections;
using System.Collections;3
 using System.ComponentModel;
using System.ComponentModel;4
 using System.Drawing;
using System.Drawing;5
 using System.Windows.Forms;
using System.Windows.Forms;6

7
 namespace Wizard
namespace Wizard8
 {
{9
 public class frmStep1 : Wizard.frmBase
 public class frmStep1 : Wizard.frmBase10
 {
 {11
 private System.Windows.Forms.TextBox txtName;
  private System.Windows.Forms.TextBox txtName;12
 private System.Windows.Forms.RadioButton rdoMale;
  private System.Windows.Forms.RadioButton rdoMale;13
 private System.Windows.Forms.RadioButton radioButton1;
  private System.Windows.Forms.RadioButton radioButton1;14
 private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label1;15
 private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label2;16
 private System.ComponentModel.IContainer components = null;
  private System.ComponentModel.IContainer components = null;17

18
 public frmStep1()
  public frmStep1()19
 {
  {20
 // 该调用是 Windows 窗体设计器所必需的。
   // 该调用是 Windows 窗体设计器所必需的。21
 InitializeComponent();
   InitializeComponent();22

23
 // TODO: 在 InitializeComponent 调用后添加任何初始化
   // TODO: 在 InitializeComponent 调用后添加任何初始化24
 }
  }25

26
 /// <summary>
  /// <summary>27
 /// 清理所有正在使用的资源。
  /// 清理所有正在使用的资源。28
 /// </summary>
  /// </summary>29
 protected override void Dispose( bool disposing )
  protected override void Dispose( bool disposing )30
 {
  {31
 if( disposing )
   if( disposing )32
 {
   {33
 if (components != null)
    if (components != null) 34
 {
    {35
 components.Dispose();
     components.Dispose();36
 }
    }37
 }
   }38
 base.Dispose( disposing );
   base.Dispose( disposing );39
 }
  }40

41
 设计器生成的代码
  设计器生成的代码114

115
 protected override void UpdateInfo()
  protected override void UpdateInfo()116
 {
  {117
 this.controller.info.Name = txtName.Text.Trim();
   this.controller.info.Name = txtName.Text.Trim();118
 this.controller.info.IsMale = rdoMale.Checked;
   this.controller.info.IsMale = rdoMale.Checked;119
 }
  }120

121
 }
 }122
 }
}第二个子窗体:
  1 using System;
using System;
2 using System.Collections;
using System.Collections;
3 using System.ComponentModel;
using System.ComponentModel;
4 using System.Drawing;
using System.Drawing;
5 using System.Windows.Forms;
using System.Windows.Forms;
6
7 namespace Wizard
namespace Wizard
8 {
{
9 public class frmStep2 : Wizard.frmBase
 public class frmStep2 : Wizard.frmBase
10 {
 {
11 private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label1;
12 private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label2;
13 private System.Windows.Forms.ComboBox cbbEduBackground;
  private System.Windows.Forms.ComboBox cbbEduBackground;
14 private System.Windows.Forms.CheckBox checkBox1;
  private System.Windows.Forms.CheckBox checkBox1;
15 private System.Windows.Forms.CheckBox checkBox2;
  private System.Windows.Forms.CheckBox checkBox2;
16 private System.Windows.Forms.CheckBox checkBox3;
  private System.Windows.Forms.CheckBox checkBox3;
17 private System.Windows.Forms.CheckBox checkBox4;
  private System.Windows.Forms.CheckBox checkBox4;
18 private System.ComponentModel.IContainer components = null;
  private System.ComponentModel.IContainer components = null;
19
20 public frmStep2()
  public frmStep2()
21 {
  {
22 // 该调用是 Windows 窗体设计器所必需的。
   // 该调用是 Windows 窗体设计器所必需的。
23 InitializeComponent();
   InitializeComponent();
24
25 // TODO: 在 InitializeComponent 调用后添加任何初始化
   // TODO: 在 InitializeComponent 调用后添加任何初始化
26 }
  }
27
28 /// <summary>
  /// <summary>
29 /// 清理所有正在使用的资源。
  /// 清理所有正在使用的资源。
30 /// </summary>
  /// </summary>
31 protected override void Dispose( bool disposing )
  protected override void Dispose( bool disposing )
32 {
  {
33 if( disposing )
   if( disposing )
34 {
   {
35 if (components != null)
    if (components != null) 
36 {
    {
37 components.Dispose();
     components.Dispose();
38 }
    }
39 }
   }
40 base.Dispose( disposing );
   base.Dispose( disposing );
41 }
  }
42
43 设计器生成的代码
  设计器生成的代码
142
143 protected override void UpdateInfo()
  protected override void UpdateInfo()
144 {
  {
145 this.controller.info.EduBackground = cbbEduBackground.GetItemText(cbbEduBackground.SelectedItem);
   this.controller.info.EduBackground = cbbEduBackground.GetItemText(cbbEduBackground.SelectedItem);
146 string lang = "";
   string lang = "";
147 foreach(Control ctl in this.Controls)
   foreach(Control ctl in this.Controls)
148 {
   {
149 if(ctl is CheckBox && ((CheckBox)ctl).Checked)
    if(ctl is CheckBox && ((CheckBox)ctl).Checked)
150 {
    {
151 lang += ctl.Text + ";";
     lang += ctl.Text + ";";
152 }
    }
153 }
   }
154 this.controller.info.ProgrameLanguage = lang;
   this.controller.info.ProgrameLanguage = lang;
155 }
  }
156
157 }
 }
158 }
}
 using System;
using System;2
 using System.Collections;
using System.Collections;3
 using System.ComponentModel;
using System.ComponentModel;4
 using System.Drawing;
using System.Drawing;5
 using System.Windows.Forms;
using System.Windows.Forms;6

7
 namespace Wizard
namespace Wizard8
 {
{9
 public class frmStep2 : Wizard.frmBase
 public class frmStep2 : Wizard.frmBase10
 {
 {11
 private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label1;12
 private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label2;13
 private System.Windows.Forms.ComboBox cbbEduBackground;
  private System.Windows.Forms.ComboBox cbbEduBackground;14
 private System.Windows.Forms.CheckBox checkBox1;
  private System.Windows.Forms.CheckBox checkBox1;15
 private System.Windows.Forms.CheckBox checkBox2;
  private System.Windows.Forms.CheckBox checkBox2;16
 private System.Windows.Forms.CheckBox checkBox3;
  private System.Windows.Forms.CheckBox checkBox3;17
 private System.Windows.Forms.CheckBox checkBox4;
  private System.Windows.Forms.CheckBox checkBox4;18
 private System.ComponentModel.IContainer components = null;
  private System.ComponentModel.IContainer components = null;19

20
 public frmStep2()
  public frmStep2()21
 {
  {22
 // 该调用是 Windows 窗体设计器所必需的。
   // 该调用是 Windows 窗体设计器所必需的。23
 InitializeComponent();
   InitializeComponent();24

25
 // TODO: 在 InitializeComponent 调用后添加任何初始化
   // TODO: 在 InitializeComponent 调用后添加任何初始化26
 }
  }27

28
 /// <summary>
  /// <summary>29
 /// 清理所有正在使用的资源。
  /// 清理所有正在使用的资源。30
 /// </summary>
  /// </summary>31
 protected override void Dispose( bool disposing )
  protected override void Dispose( bool disposing )32
 {
  {33
 if( disposing )
   if( disposing )34
 {
   {35
 if (components != null)
    if (components != null) 36
 {
    {37
 components.Dispose();
     components.Dispose();38
 }
    }39
 }
   }40
 base.Dispose( disposing );
   base.Dispose( disposing );41
 }
  }42

43
 设计器生成的代码
  设计器生成的代码142

143
 protected override void UpdateInfo()
  protected override void UpdateInfo()144
 {
  {145
 this.controller.info.EduBackground = cbbEduBackground.GetItemText(cbbEduBackground.SelectedItem);
   this.controller.info.EduBackground = cbbEduBackground.GetItemText(cbbEduBackground.SelectedItem);146
 string lang = "";
   string lang = "";147
 foreach(Control ctl in this.Controls)
   foreach(Control ctl in this.Controls)148
 {
   {149
 if(ctl is CheckBox && ((CheckBox)ctl).Checked)
    if(ctl is CheckBox && ((CheckBox)ctl).Checked)150
 {
    {151
 lang += ctl.Text + ";";
     lang += ctl.Text + ";";152
 }
    }153
 }
   }154
 this.controller.info.ProgrameLanguage = lang;
   this.controller.info.ProgrameLanguage = lang;155
 }
  }156

157
 }
 }158
 }
}测试Demo:
  1 using System;
using System;
2 using System.Drawing;
using System.Drawing;
3 using System.Collections;
using System.Collections;
4 using System.ComponentModel;
using System.ComponentModel;
5 using System.Windows.Forms;
using System.Windows.Forms;
6
7 namespace Wizard
namespace Wizard
8 {
{
9 /// <summary>
    /// <summary>
10 /// frmTest 的摘要说明。
    /// frmTest 的摘要说明。
11 /// </summary>
    /// </summary>
12 public class frmTest : System.Windows.Forms.Form
    public class frmTest : System.Windows.Forms.Form
13 {
    {
14 /// <summary>
        /// <summary>
15 /// 必需的设计器变量。
        /// 必需的设计器变量。
16 /// </summary>
        /// </summary>
17 private System.ComponentModel.Container components = null;
        private System.ComponentModel.Container components = null;
18 private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button1;
19 private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button2;
20 private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label1;
21 private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label2;
22 private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label3;
23 private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label4;
24 private WizardController wizard;
        private WizardController wizard;
25
26 public frmTest()
        public frmTest()
27 {
        {
28 //
            //
29 // Windows 窗体设计器支持所必需的
            // Windows 窗体设计器支持所必需的
30 //
            //
31 InitializeComponent();
            InitializeComponent();
32
33 //
            //
34 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
35 //
            //
36 }
        }
37
38 /// <summary>
        /// <summary>
39 /// 清理所有正在使用的资源。
        /// 清理所有正在使用的资源。
40 /// </summary>
        /// </summary>
41 protected override void Dispose( bool disposing )
        protected override void Dispose( bool disposing )
42 {
        {
43 if( disposing )
            if( disposing )
44 {
            {
45 if(components != null)
                if(components != null)
46 {
                {
47 components.Dispose();
                    components.Dispose();
48 }
                }
49 }
            }
50 base.Dispose( disposing );
            base.Dispose( disposing );
51 }
        }
52
53 Windows 窗体设计器生成的代码
        Windows 窗体设计器生成的代码
130 /// <summary>
        /// <summary>
131 /// 应用程序的主入口点。
        /// 应用程序的主入口点。
132 /// </summary>
        /// </summary>
133 [STAThread]
        [STAThread]
134 static void Main()
        static void Main()
135 {
        {
136 Application.Run(new frmTest());
            Application.Run(new frmTest());
137 }
        }
138
139 private void button1_Click(object sender, System.EventArgs e)
        private void button1_Click(object sender, System.EventArgs e)
140 {
        {
141 this.wizard = new WizardController();
            this.wizard = new WizardController();
142 this.wizard.BeginWizard();
            this.wizard.BeginWizard();
143 }
        }
144
145 private void button2_Click(object sender, System.EventArgs e)
        private void button2_Click(object sender, System.EventArgs e)
146 {
        {
147 if(this.wizard != null && this.wizard.info != null)
            if(this.wizard != null && this.wizard.info != null)
148 {
            {
149 this.label1.Text = this.wizard.info.Name;
                this.label1.Text = this.wizard.info.Name;
150 if(this.wizard.info.IsMale)
                if(this.wizard.info.IsMale)
151 this.label2.Text = "男";
                    this.label2.Text = "男";
152 else
                else
153 this.label2.Text = "女";
                    this.label2.Text = "女";
154 this.label3.Text = this.wizard.info.EduBackground;
                this.label3.Text = this.wizard.info.EduBackground;
155 this.label4.Text = this.wizard.info.ProgrameLanguage;
                this.label4.Text = this.wizard.info.ProgrameLanguage;
156 }
            }
157 else
            else
158 {
            {
159 MessageBox.Show("NULL");
                MessageBox.Show("NULL");
160 }
            }
161 }
        }
162 }
    }
163 }
}
 using System;
using System;2
 using System.Drawing;
using System.Drawing;3
 using System.Collections;
using System.Collections;4
 using System.ComponentModel;
using System.ComponentModel;5
 using System.Windows.Forms;
using System.Windows.Forms;6

7
 namespace Wizard
namespace Wizard8
 {
{9
 /// <summary>
    /// <summary>10
 /// frmTest 的摘要说明。
    /// frmTest 的摘要说明。11
 /// </summary>
    /// </summary>12
 public class frmTest : System.Windows.Forms.Form
    public class frmTest : System.Windows.Forms.Form13
 {
    {14
 /// <summary>
        /// <summary>15
 /// 必需的设计器变量。
        /// 必需的设计器变量。16
 /// </summary>
        /// </summary>17
 private System.ComponentModel.Container components = null;
        private System.ComponentModel.Container components = null;18
 private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button1;19
 private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button2;20
 private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label1;21
 private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label2;22
 private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label3;23
 private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label4;24
 private WizardController wizard;
        private WizardController wizard;25

26
 public frmTest()
        public frmTest()27
 {
        {28
 //
            //29
 // Windows 窗体设计器支持所必需的
            // Windows 窗体设计器支持所必需的30
 //
            //31
 InitializeComponent();
            InitializeComponent();32

33
 //
            //34
 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码35
 //
            //36
 }
        }37

38
 /// <summary>
        /// <summary>39
 /// 清理所有正在使用的资源。
        /// 清理所有正在使用的资源。40
 /// </summary>
        /// </summary>41
 protected override void Dispose( bool disposing )
        protected override void Dispose( bool disposing )42
 {
        {43
 if( disposing )
            if( disposing )44
 {
            {45
 if(components != null)
                if(components != null)46
 {
                {47
 components.Dispose();
                    components.Dispose();48
 }
                }49
 }
            }50
 base.Dispose( disposing );
            base.Dispose( disposing );51
 }
        }52

53
 Windows 窗体设计器生成的代码
        Windows 窗体设计器生成的代码130
 /// <summary>
        /// <summary>131
 /// 应用程序的主入口点。
        /// 应用程序的主入口点。132
 /// </summary>
        /// </summary>133
 [STAThread]
        [STAThread]134
 static void Main()
        static void Main()135
 {
        {136
 Application.Run(new frmTest());
            Application.Run(new frmTest());137
 }
        }138

139
 private void button1_Click(object sender, System.EventArgs e)
        private void button1_Click(object sender, System.EventArgs e)140
 {
        {141
 this.wizard = new WizardController();
            this.wizard = new WizardController();142
 this.wizard.BeginWizard();
            this.wizard.BeginWizard();143
 }
        }144

145
 private void button2_Click(object sender, System.EventArgs e)
        private void button2_Click(object sender, System.EventArgs e)146
 {
        {147
 if(this.wizard != null && this.wizard.info != null)
            if(this.wizard != null && this.wizard.info != null)148
 {
            {149
 this.label1.Text = this.wizard.info.Name;
                this.label1.Text = this.wizard.info.Name;150
 if(this.wizard.info.IsMale)
                if(this.wizard.info.IsMale)151
 this.label2.Text = "男";
                    this.label2.Text = "男";152
 else
                else153
 this.label2.Text = "女";
                    this.label2.Text = "女";154
 this.label3.Text = this.wizard.info.EduBackground;
                this.label3.Text = this.wizard.info.EduBackground;155
 this.label4.Text = this.wizard.info.ProgrameLanguage;
                this.label4.Text = this.wizard.info.ProgrameLanguage;156
 }
            }157
 else
            else158
 {
            {159
 MessageBox.Show("NULL");
                MessageBox.Show("NULL");160
 }
            }161
 }
        }162
 }
    }163
 }
} 
                    
                

 
                
            
         
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号