1.FormBase界面:有“帮助,上一步,下一步,取消”按钮,这些按钮放置在一个Panel上。
namespace DataBase
{
    public partial class FormBase : Form
    {
        public FormBase()
        {
            InitializeComponent(); 
        }
        public WizardController controller = null;
 
        #region 函数
        /// <summary>
        /// 自定义函数
        /// </summary>
        public void DisableButton()
        {
            if (this.controller == null)
                return;
            if (this.controller.IsFirstForm)
            {
                this.buttonPrev.Enabled = false;
            }
            else
            {
                this.buttonPrev.Enabled = true;
            }
            if (this.controller.IsLastForm) //如果是向导的最后一个页面,显示“完成”
            {
                this.buttonNext.Text = "完成";
            }
            else    //否则显示“下一步”
            {
                this.buttonNext.Text = "下一步";
            }
        }
        protected virtual void UpdateInfo()  //由“每一步FormStep1,FormStep2…”的界面 具体实现
        {
 
        }
        protected virtual void GoNext()
        {
            UpdateInfo();
            if (this.controller.IsLastForm) //如果是向导的最后一个页面,则调用“FinishWizard()”
            {
                controller.FinishWizard();
                this.Visible = false;
            }
            else//如果是向导的最后一个页面,则调用“GoNext()”
            {
                controller.GoNext();
            }
        }
        protected virtual void GoPrev()
        {
            UpdateInfo();
            controller.GoPrev();
        }
        //protected virtual void Finish()
        //{
        //    UpdateInfo();
        //    controller.FinishWizard();
        //    this.Visible = false;
        //}
        protected virtual void Cancel()
        {
            this.controller.info = null;
            this.Close();
        }
        #endregion
 
        #region 界面控件事件
        /// <summary>
        /// 界面控件事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonPrev_Click(object sender, EventArgs e)
        {
            GoPrev();
        }
        private void buttonNext_Click(object sender, EventArgs e)
        {
            GoNext();
        }
 
        //private void buttonFinish_Click(object sender, EventArgs e)
        //{
        //    Finish();
        //}
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Cancel();
        }
        #endregion   
    }
}
 
2.一个WizardController.cs文件(非界面)
namespace DataBase
{
    public class WizardController
    {
        private ArrayList WizardForms = new ArrayList();
        private int curIndex = 0;
 
        #region 构造函数
        /// <summary>
        ///构造函数
        /// </summary>
        public WizardController()
        {
            WizardForms.Add(new FormStep1()); //frmStep1继承自FormBase
            WizardForms.Add(new FormStep2());
            WizardForms.Add(new FormStep3());
            foreach (FormBase frm in WizardForms)
            {
                frm.controller = this;
                frm.DisableButton();
            }
        }
        #endregion
 
        #region 自定义函数
        /// <summary>
        /// 自定义函数
        /// </summary>
 
        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;
                curIndex++;
            }
            else
            {
                return;
            }
            ((FormBase)WizardForms[curIndex]).Show();
            ((FormBase)WizardForms[curIndex]).DisableButton();
        }
 
        public void GoPrev()
        {
            if (curIndex - 1 >= 0)
            {
                ((FormBase)WizardForms[curIndex]).Visible = false;
                curIndex--;
            }
            else
            {
                return;
            }
            ((FormBase)WizardForms[curIndex]).Show();
            ((FormBase)WizardForms[curIndex]).DisableButton();
        }
 
        public void BeginWizard()
        {
            ((FormBase)WizardForms[0]).Show();
            ((FormBase)WizardForms[curIndex]).DisableButton();
        }
 
        public void FinishWizard()
        {
            curIndex = 0;
            Dispose();
        }
 
        private void Dispose()
        {
            foreach (FormBase frm in WizardForms)
            {
                frm.Close();
            }
        }
        #endregion
    }
}
 
3. FormStep1界面继承自FormBase,上面有一个Label控件,Text属性“This is FormStep1”
namespace DataBase
{
    public partial class FormStep1 : DataBase.FormBase
    {
        public FormStep1()
        {
            InitializeComponent();
        }
 
        protected override void UpdateInfo()
        {
            MessageBox.Show("第一步!","Step1",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }
    }
}
 
4. FormStep2界面继承自FormBase,上面有一个Label控件,Text属性“This is FormStep2”
namespace DataBase
{
    public partial class FormStep2 : DataBase.FormBase
    {
        public FormStep2()
        {
            InitializeComponent();
        }
 
        protected override void UpdateInfo()
        {
            MessageBox.Show("第二步!", "Step2", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
 
5. FormStep3界面继承自FormBase,上面有一个Label控件,Text属性“This is FormStep3”
namespace DataBase
{
    public partial class FormStep3 : DataBase.FormBase
    {
        public FormStep3()
        {
            InitializeComponent();
        }
        protected override void UpdateInfo()
        {
            MessageBox.Show("第三步!", "Step3", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
6.FormTestWizard界面,上面一个buttonText属性“启动向导”
namespace DataBase
{
    public partial class FormTestWizard : Form
    {
        public FormTestWizard()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            WizardController controller = new WizardController();
            controller.BeginWizard();
        }
    }
}
 
7.修改程序的启动界面为“FormTestWizard
namespace DataBase
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormTestWizard());  //启动界面
        }
    }
}

C# 制作向导的更多相关文章

  1. 使用CocosSharp制作一个游戏 - CocosSharp中文教程

    注:本教程翻译自官方<Walkthrough - Building a game with CocosSharp>,官方教程有很多地方说的不够详细,或者代码不全,导致无法继续,本人在看了G ...

  2. 使用Setup Factory安装包制作工具制作安装包

    在我们开发完软件后,除了极个别案例我们把整个目录复制给客户用外,我们一般都需要做成安装包,方便整个软件的部署操作,以安装包的部署操作可能简单的是复制文件,也可能包括一些注册表.数据库等额外的操作,不过 ...

  3. 安装包制作工具 SetupFactory使用1 详解

    2014-11-19 Setup Factory 是一个强大的安装程序制作工具.提供了安装制作向导界面,即使你对安装制作不了解,也可以生成专业性质的安装程序.可建立快捷方式,也可直接在 Windows ...

  4. Inno Setup制作应用程序安装包

    我最近写了一个MFC应用程序,想发给其他的小伙伴玩一玩,直接发了个exe文件过去,结果发现小伙伴那边打不开.原来这个exe文件虽然是MFC静态编译的,但是还依赖了其他几个.dll文件,需要把这几个dl ...

  5. 您还差宝贝一张语文教学光盘!教你如何制作ISO文件

    1 大家没有发现 宝宝初上小学无法专心地做作业.读书? 我家的宝贝就是这样 做作业时 总是东搞搞,西弄弄 完全无法专心 再不就是不耐心 读一遍课本就觉得累 读三两遍就说学习是个苦差事儿 2 一直以来 ...

  6. 安装包制作工具 SetupFactory 详解

    Setup Factory 是一个强大的安装程序制作工具.提供了安装制作向导界面,即使你对安装制作不了解,也可以生成专业性质的安装程序.可建立快捷方式,也可直接在 Windows 系统的注册表加入内容 ...

  7. WinPE启动U盘的制作方法与软件下载(通用PE工具箱/老毛桃/大白菜WinPE)

    转自:http://blog.sina.com.cn/s/blog_58c380370100cp5x.html 文件大小:39.5M(支持Win7安装,早期的通用PE工具箱,小巧不过几十兆,现在都臃肿 ...

  8. 00 Cadence学习总目录

    这个系列是我学习于博士CADENCE视频教程60讲时,一边学一边记的笔记.使用的CADENCE16.6. 01-03课 了解软件 创建工程 创建元件库 分裂元件的制作方法 04课 正确使用hetero ...

  9. Android驱动开发5-8章读书笔记

    Android驱动开发读书笔记                                                              第五章 S5PV210是一款32位处理器,具有 ...

随机推荐

  1. EF 事物Transaction简单操作

    /// <summary> /// 申请提现 /// </summary> /// <param name="userId">用户id</ ...

  2. ubuntu 18.04/18.10解决create-react-app:command not found问题

    npm config set prefix /usr/local sudo npm install -g create-react-app create-react-app my-app

  3. 上架一台Cisco防火墙及其架构

    领导给小白两条线,分别是电源线和网线,去吧,机房上架一台防火墙... 额, 然后小白抱着防火墙就去了...

  4. 将本地时间转换成 UTC 时间,0时区时间

    // 将时间戳转换成日期格式: function timestampToTime(timestamp) { var date = new Date(timestamp);//时间戳为10位需*1000 ...

  5. 在eclipse中从cvs下载项目,再部署到tomcat常见错误!

    1.先调出cvs视图 如果cvs插件还未安装,下载一个: 安装cvs插件:将features和pluguns文件夹里面的内容分别复制到eclipse安装路径下面对应的features和pluguns文 ...

  6. 表单相关标签之textarea,select

    textarea <textarea rows="3" cols="20"> 在w3school,你可以找到你所需要的所有的网站建设教程. < ...

  7. 【mmall】IDEA中Service层无法识别Mapper,但是代码通过问题

    解决方案

  8. Java学习过程中要记录的地方--汇总

    1.Map的子类 HashMap 是哈希表,根据哈希算法来存的,取出来不一定是按照原来的循序: Ctrl+T 可以看到 HashMap下面有 LinkHashMap 是线性实现的,里面有顺序. --- ...

  9. 微信小程序入门八头像上传

    1. action-sheet 底部弹出可选菜单组件 2. wx.uploadFile 将本地资源上传到服务器 3. wx.chooseImage 从本地相册选择图片或使用相机拍照. 4. wx.pr ...

  10. Light oj 1099 - Not the Best 次短路

    题目大意:求次短路. 题目思路:由于可能存在重边的情况所以不能采用邻接矩阵储存图,我用了邻接表来存图. 由起点S到终点E的次短路可能由以下情况组成: 1.S到v点的次短路 + v到E的距离 2.S到v ...