WWF 工作流学习笔记(三进街)

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Workflow.Activities;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel;

 

namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        private WorkflowView wlv;
        private WorkflowViewWrapper workflowViewWrapper;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //这样是错误的
           // wlv = new WorkflowView();
           // this.panel1.Controls.Add(wlv);

            //这个是正确的
            this.workflowViewWrapper=new WorkflowViewWrapper(this);
            this.panel1.Controls.Add(this.workflowViewWrapper.workflowView);
            this.workflowViewWrapper.LoadDefaulttWorkflow();
        }
    }

    public class WorkflowViewWrapper
    {
        private DesignSurface surface;
        public WorkflowView workflowView;
        private IDesignerHost host;
        private SequentialWorkflowActivity sequentialWorkflow;

        public WorkflowViewWrapper(Form parent)
        {
             //Create a Workflow Design Surface
            //创建设计时的环境以显示WorkflowView
            this.surface = new DesignSurface();

            //Get the Workflow Designer Host
            //获得管理设计器的接口对象
            this.host=this.surface.GetService(typeof(IDesignerHost)) as IDesignerHost;
            if(this.host==null)
                return;
           
            //Create a Sequential Workflow by using the Workflow Designer Host
            sequentialWorkflow=(SequentialWorkflowActivity)host.CreateComponent(typeof(SequentialWorkflowActivity));
            //sequentialWorkflow.ID=\"SequentialWorkflow1\";
           
            //Create a Workflow view on the workflow Design surface
            //指定的Surface显示WorkflowView
            this.workflowView=new WorkflowView(this.surface as IServiceProvider);
            this.workflowView.Dock=DockStyle.Fill;

            //Activate the Workflow view
            this.host.Activate();
        }

        public void LoadDefaulttWorkflow()
        {
            //Create a code activity
            CodeActivity CodeActivity1= new CodeActivity();
            sequentialWorkflow.Activities.Add(CodeActivity1);
            host.RootComponent.Site.Container.Add(CodeActivity1);
        }

    }  
}

[img]http://p.blog.csdn.net/images/p_blog_csdn_net/Eroschina/20060627.gif[/img]

posted @ 2007-04-16 22:10  理财顾问  阅读(963)  评论(0编辑  收藏  举报