使用C#创建一个安装向导
2010-09-30 21:05:21 来源:WEB开发网IsLastForm:是否是最后一个窗体。
IWBParameters:Install Wizard Base Parameters,安装向导支持的参数。
ProgramName:所要安装的程序名。
方法:
AddForms():向Controller控件添加窗体实例。
BeginWizard():启动向导。
Dispose():清理系统资源。
FinishWizard():完成向导。
GoNext():执行下一步。
GoPrev():执行上一步。
代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace B1Plus.InstallWizardBase
{
public class WizardController
{
private ArrayList _WizardForms = new ArrayList();
private int _curIndex = 0;
private object _IWBParameters = null;
public object IWBParameters
{
get { return _IWBParameters; }
set { _IWBParameters = value; }
}
public int CurIndex
{
get { return this._curIndex; }
}
public int FormsCount
{
get { return this._WizardForms.Count; }
}
#region 构造函数
/// <summary>
///构造函数
/// </summary>
public WizardController()
{
}
#endregion
public void AddForms(FormBase formBase)
{
_WizardForms.Add(formBase);
foreach (FormBase frm in _WizardForms)
{
frm.controller = this;
//frm.DisableButtons();
if (this._ProgramName != null)
frm.Text = "欢迎使用 " + this._ProgramName + " 安装向导";
else
{
frm.Text = "B1Plus InstallWizard.";
}
}
}
string _ProgramName = null;
public string ProgramName
{
get { return this._ProgramName; }
set { this._ProgramName = value; }
}
public bool IsFirstForm //属性
{
get { return _curIndex == 0; }
}
public bool IsLastForm //属性
{
get { return _curIndex == this._WizardForms.Count - 1; }
}
public void GoNext()
{
if (_curIndex + 1 < _WizardForms.Count)
{
//((FormBase)_WizardForms[_curIndex]).Visible = false;
((FormBase)_WizardForms[_curIndex]).Hide();
_curIndex++;
}
else
{
return;
}
((FormBase)_WizardForms[_curIndex]).DisableButtons();
((FormBase)_WizardForms[_curIndex]).Show();
}
public void GoPrev()
{
if (_curIndex - 1 >= 0)
{
((FormBase)_WizardForms[_curIndex]).Hide();
_curIndex--;
}
else
{
return;
}
((FormBase)_WizardForms[_curIndex]).DisableButtons();
((FormBase)_WizardForms[_curIndex]).Show();
}
public void BeginWizard()
{
((FormBase)_WizardForms[_curIndex]).DisableButtons();
((FormBase)_WizardForms[0]).Show();
}
public void FinishWizard()
{
_curIndex = 0;
Dispose();
}
private void Dispose()
{
foreach (FormBase frm in _WizardForms)
{
frm.Close();
}
Application.Exit();
}
}
}
更多精彩
赞助商链接