Share via


Tâche 2 : créer le Windows Form d'hébergement du concepteur de workflow

Dans cette tâche, vous créez l'application hôte utilisée dans le didacticiel. L'application se compose d'un contrôle Panneau qui sera utilisé pour héberger le concepteur Windows Workflow Foundation. Sous le contrôle Panneau, une zone de texte est utilisée pour permettre à un utilisateur d'entrer le code XAML et d'afficher graphiquement et automatiquement les résultats de ce code dans le concepteur de workflow.

Dans le reste du didacticiel, vous ajouterez le code restant requis afin d'afficher le concepteur de workflow Windows sur votre Windows Form.

NoteRemarque :

Bien qu'il soit conseillé de suivre les exercices de façon linéaire, ce n'est pas requis. Vous pouvez démarrer cet exercice en ouvrant l'exemple de projet et en continuant avec les étapes de la section suivante.

Pour créer le fichier de code source Windows Form

  • Dans votre répertoire de projets, créez un nouveau fichier nommé WFEditForm.

Attribuez-lui une extension .cs si vous créez une application C# ou .vb si vous créez une application Visual Basic.

  1. Dans votre fichier projet principal (WFEdit), insérez un nouvel élément ItemGroup avant l'élément Import à la fin du fichier.

  2. Dans l'élément ItemGroup, ajoutez un nouvel élément Compile.

  3. Ajoutez un nouvel attribut à l'élément Compile nommé Include à l'aide du nom de fichier que vous avez créé à l'étape 1 en guise de valeur d'attribut.

  4. Ajoutez un nouvel élément enfant à l'élément Compile, nommé SubType.

    Affectez la valeur Form à cet élément. Votre nœud ItemGroup s'affichera comme suit :

    <ItemGroup>
        <Compile Include="WFEditForm.vb">
          <SubType>Form</SubType>
        </Compile>
    </ItemGroup>
    
    <ItemGroup>
        <Compile Include="WFEditForm.cs">
          <SubType>Form</SubType>
        </Compile>
    </ItemGroup>
    

Pour ajouter le code Windows Form à l'application hôte

  • Dans le fichier de code source WFEditForm, ajoutez le code suivant pour l'application Windows Form.

    namespace Microsoft.Samples.Workflow.Quickstarts.WFEdit
    {
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Text;
        using System.Windows.Forms;
        using System.Workflow.ComponentModel.Design;
        using System.ComponentModel.Design;
        using System.Workflow.ComponentModel;
        using System.Workflow.Activities;
        using System.IO;
        using System.Xml;
        using System.Workflow.ComponentModel.Serialization;
        using System.Collections;
    
        public class WFEditForm : Form
        {
            private System.ComponentModel.IContainer components = null;
            private System.Windows.Forms.SplitContainer splitContainer1;
            private System.Windows.Forms.TextBox xamlView;
            private System.Windows.Forms.Panel placeHolderPanel;
    
            public WFEditForm()
            {
                InitializeComponent();
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            private void InitializeComponent()
            {
                this.splitContainer1 = new System.Windows.Forms.SplitContainer();
                this.placeHolderPanel = new System.Windows.Forms.Panel();
                this.xamlView = new System.Windows.Forms.TextBox();
                this.splitContainer1.Panel1.SuspendLayout();
                this.splitContainer1.Panel2.SuspendLayout();
                this.splitContainer1.SuspendLayout();
                this.SuspendLayout();
                // 
                // splitContainer1
                // 
                this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.splitContainer1.Location = new System.Drawing.Point(0, 0);
                this.splitContainer1.Name = "splitContainer1";
                this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
                // 
                // splitContainer1.Panel1
                // 
                this.splitContainer1.Panel1.Controls.Add(this.placeHolderPanel);
                // 
                // splitContainer1.Panel2
                // 
                this.splitContainer1.Panel2.Controls.Add(this.xamlView);
                this.splitContainer1.Size = new System.Drawing.Size(736, 620);
                this.splitContainer1.SplitterDistance = 245;
                this.splitContainer1.TabIndex = 0;
                // 
                // placeHolderPanel
                // 
                this.placeHolderPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.placeHolderPanel.Location = new System.Drawing.Point(0, 0);
                this.placeHolderPanel.Name = "placeHolderPanel";
                this.placeHolderPanel.Size = new System.Drawing.Size(736, 245);
                this.placeHolderPanel.TabIndex = 0;
                // 
                // xamlView
                // 
                this.xamlView.Dock = System.Windows.Forms.DockStyle.Fill;
                this.xamlView.Location = new System.Drawing.Point(0, 0);
                this.xamlView.Multiline = true;
                this.xamlView.Name = "xamlView";
                this.xamlView.Size = new System.Drawing.Size(736, 371);
                this.xamlView.TabIndex = 1;
                this.xamlView.TextChanged += new System.EventHandler(this.xamlView_TextChanged);
                // 
                // WFEditForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(736, 620);
                this.Controls.Add(this.splitContainer1);
                this.Name = "WFEditForm";
                this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
                this.Text = "WFEdit";
                this.splitContainer1.Panel1.ResumeLayout(false);
                this.splitContainer1.Panel2.ResumeLayout(false);
                this.splitContainer1.Panel2.PerformLayout();
                this.splitContainer1.ResumeLayout(false);
                this.ResumeLayout(false);
    
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
            }
    
            private void xamlView_TextChanged(object sender, EventArgs e)
            {
            }
        }
    }
    

Pour créer le fichier source du point d'entrée de l'application

  1. Dans votre répertoire de projets, créez un nouveau fichier nommé Program.

  2. Attribuez une extension .cs au fichier si vous créez une application C# ou .vb si vous créez une application Visual Basic.

  3. Dans votre fichier projet principal (RulesAndConditions), dans l'élément ItemGroup que vous avez créé dans la première procédure, ajoutez un nouvel élément Compile.

  4. Ajoutez un nouvel attribut à l'élément Compile, nommé Include.

    Utilisez le nom de fichier que vous avez créé à l'étape 1 pour la valeur d'attribut.

  5. Votre nœud ItemGroup final s'affichera comme suit :

    <ItemGroup>
        <Compile Include="PointOfSaleSimulator.vb">
            <SubType>Form</SubType>
        </Compile>
        <Compile Include="Program.vb" />
    </ItemGroup>
    
    <ItemGroup>
        <Compile Include="PointOfSaleSimulator.cs">
            <SubType>Form</SubType>
        </Compile>
        <Compile Include="Program.cs" />
    </ItemGroup>
    

Pour ajouter le code du point d'entrée de l'application

  1. Dans le fichier programme que vous avez créé dans la procédure précédente, ajoutez le code suivant pour ouvrir l'application Windows Form lorsque votre application démarre.

    namespace Microsoft.Samples.Workflow.Quickstarts.WFEdit
    {
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Text;
        using System.Windows.Forms;
        using System.Workflow.ComponentModel.Design;
        using System.ComponentModel.Design;
        using System.Workflow.ComponentModel;
        using System.Workflow.Activities;
        using System.IO;
        using System.Xml;
        using System.Workflow.ComponentModel.Serialization;
        using System.Collections;
    
        public class WFEditForm : Form
        {
            private System.ComponentModel.IContainer components = null;
            private System.Windows.Forms.SplitContainer splitContainer1;
            private System.Windows.Forms.TextBox xamlView;
            private System.Windows.Forms.Panel placeHolderPanel;
    
            public WFEditForm()
            {
                InitializeComponent();
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            private void InitializeComponent()
            {
                this.splitContainer1 = new System.Windows.Forms.SplitContainer();
                this.placeHolderPanel = new System.Windows.Forms.Panel();
                this.xamlView = new System.Windows.Forms.TextBox();
                this.splitContainer1.Panel1.SuspendLayout();
                this.splitContainer1.Panel2.SuspendLayout();
                this.splitContainer1.SuspendLayout();
                this.SuspendLayout();
                // 
                // splitContainer1
                // 
                this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.splitContainer1.Location = new System.Drawing.Point(0, 0);
                this.splitContainer1.Name = "splitContainer1";
                this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
                // 
                // splitContainer1.Panel1
                // 
                this.splitContainer1.Panel1.Controls.Add(this.placeHolderPanel);
                // 
                // splitContainer1.Panel2
                // 
                this.splitContainer1.Panel2.Controls.Add(this.xamlView);
                this.splitContainer1.Size = new System.Drawing.Size(736, 620);
                this.splitContainer1.SplitterDistance = 245;
                this.splitContainer1.TabIndex = 0;
                // 
                // placeHolderPanel
                // 
                this.placeHolderPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.placeHolderPanel.Location = new System.Drawing.Point(0, 0);
                this.placeHolderPanel.Name = "placeHolderPanel";
                this.placeHolderPanel.Size = new System.Drawing.Size(736, 245);
                this.placeHolderPanel.TabIndex = 0;
                // 
                // xamlView
                // 
                this.xamlView.Dock = System.Windows.Forms.DockStyle.Fill;
                this.xamlView.Location = new System.Drawing.Point(0, 0);
                this.xamlView.Multiline = true;
                this.xamlView.Name = "xamlView";
                this.xamlView.Size = new System.Drawing.Size(736, 371);
                this.xamlView.TabIndex = 1;
                this.xamlView.TextChanged += new System.EventHandler(this.xamlView_TextChanged);
                // 
                // WFEditForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(736, 620);
                this.Controls.Add(this.splitContainer1);
                this.Name = "WFEditForm";
                this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
                this.Text = "WFEdit";
                this.splitContainer1.Panel1.ResumeLayout(false);
                this.splitContainer1.Panel2.ResumeLayout(false);
                this.splitContainer1.Panel2.PerformLayout();
                this.splitContainer1.ResumeLayout(false);
                this.ResumeLayout(false);
    
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
            }
    
            private void xamlView_TextChanged(object sender, EventArgs e)
            {
            }
        }
    }
    
  2. Générez et exécutez l'application.

Compilation du code

Pour plus d'informations sur la compilation de votre code, consultez Compilation du code.

Voir aussi

Concepts

Hébergement de concepteurs de workflows

Autres ressources

Basic Designer Hosting Sample
Outlook Workflow Wizard Sample
Workflow Monitor Sample
Tracking Profile Designer Sample

Footer image

Copyright ©2007 par Microsoft Corporation. Tous droits réservés.