Share via


Task 2: Create the Custom Activity Host Application

Download sample

In this task, you create the host application that is used in this tutorial.

The application that you build for the tutorial is a text-based Web browser that is built using a Windows Form. The form contains a text box, which is used to enter a Web page address and a button, which is labeled Go. When the button is clicked, the application loads and starts the sequential workflow. This workflow contains a single custom activity that performs the task of downloading the text of the Web page.

Note

Although you are encouraged to follow the exercises in a linear manner, it is not required. You can start this exercise by opening the sample project and proceeding to the steps in the following section.

To create the Windows Form source code file in Visual Studio

  1. Right-click Form1 in Solution Explorer, and choose Rename. Change its name to Mainform, and confirm that references should be updated.

  2. Right-click Mainform in Solution Explorer and select View Code to open it in the code editor on the left pane. Replace the code in the Mainform class with the following:

    using System.Workflow.Runtime;
    
  3. Add the following method to the Mainform class.

    private void goButton_Click(object sender, EventArgs e)
    {
    }
    
  4. In the Mainform.Designer file, replace the body of the InitializeComponent method (in the Windows Form Designer generated code region) with the following.

    this.addressCaption = new System.Windows.Forms.Label();
    this.address = new System.Windows.Forms.TextBox();
    this.data = new System.Windows.Forms.TextBox();
    this.goButton = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // addressCaption
    // 
    this.addressCaption.AutoSize = true;
    this.addressCaption.Location = new System.Drawing.Point(15, 13);
    this.addressCaption.Name = "addressCaption";
    this.addressCaption.Size = new System.Drawing.Size(41, 13);
    this.addressCaption.TabIndex = 0;
    this.addressCaption.Text = "Address";
    // 
    // address
    // 
    this.address.Anchor = ((System.Windows.Forms.AnchorStyles)
        (((System.Windows.Forms.AnchorStyles.Top |
        System.Windows.Forms.AnchorStyles.Left) |
        System.Windows.Forms.AnchorStyles.Right)));
    this.address.Location = new System.Drawing.Point(16, 28);
    this.address.Name = "address";
    this.address.Size = new System.Drawing.Size(430, 20);
    this.address.TabIndex = 0;
    this.address.Text = "http://";
    // 
    // data
    // 
    this.data.Anchor = ((System.Windows.Forms.AnchorStyles)
        ((((System.Windows.Forms.AnchorStyles.Top |
        System.Windows.Forms.AnchorStyles.Bottom) |
        System.Windows.Forms.AnchorStyles.Left) |
        System.Windows.Forms.AnchorStyles.Right)));
    this.data.Location = new System.Drawing.Point(15, 55);
    this.data.Multiline = true;
    this.data.Name = "data";
    this.data.ReadOnly = true;
    this.data.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    this.data.Size = new System.Drawing.Size(496, 320);
    this.data.TabIndex = 2;
    // 
    // goButton
    // 
    this.goButton.Location = new System.Drawing.Point(462, 25);
    this.goButton.Name = "goButton";
    this.goButton.Size = new System.Drawing.Size(49, 23);
    this.goButton.TabIndex = 1;
    this.goButton.Text = "Go";
    this.goButton.Anchor = ((System.Windows.Forms.AnchorStyles)
        ((System.Windows.Forms.AnchorStyles.Top |
        System.Windows.Forms.AnchorStyles.Right)));
    this.goButton.Click += new System.EventHandler(this.goButton_Click);
    // 
    // MainForm
    // 
    this.AcceptButton = this.goButton;
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(523, 407);
    this.Controls.Add(this.goButton);
    this.Controls.Add(this.data);
    this.Controls.Add(this.address);
    this.Controls.Add(this.addressCaption);
    this.Name = "MainForm";
    this.Text = "Web Tear";
    this.ResumeLayout(false);
    this.PerformLayout();
    
  5. Add the following member declarations to the Mainform class in the Mainform file.

    private System.Windows.Forms.Label addressCaption;
    private System.Windows.Forms.TextBox address;
    private System.Windows.Forms.TextBox data;
    private System.Windows.Forms.Button goButton;
    

Compiling the Code

For information about compiling your code, see Compiling the Code.

Run the application in the \bin\debug folder (or the \bin folder if you are using Visual Basic .NET). Your application will appear similar to the following figure.

Output from Task 2

In Task 3: Create the Custom Activity Sequential Workflow, you create a basic sequential workflow that you build on later.

Run the application in the \bin\debug folder (or the \bin folder if you are using Visual Basic .NET).

See Also

Concepts

Creating a Workflow Host Application

Other Resources

Task 3: Create the Custom Activity Sequential Workflow
Tutorial: Create a Custom WF Activity
Custom Activities

Copyright © 2007 by Microsoft Corporation. All rights reserved.
Last Published: 2010-03-04