Export (0) Print
Expand All

ActivityDesigner Class

Provides a mandatory base class for all activity designer components.

Namespace: System.Workflow.ComponentModel.Design
Assembly: System.Workflow.ComponentModel (in system.workflow.componentmodel.dll)

public class ActivityDesigner : IDesignerFilter, IToolboxUser, IPersistUIState, 
	IWorkflowRootDesigner, IRootDesigner, IDesigner, IDisposable
public class ActivityDesigner implements IDesignerFilter, IToolboxUser, 
	IPersistUIState, IWorkflowRootDesigner, IRootDesigner, IDesigner, IDisposable
public class ActivityDesigner implements IDesignerFilter, IToolboxUser, 
	IPersistUIState, IWorkflowRootDesigner, IRootDesigner, IDesigner, IDisposable
Not applicable.

All activity designer components derive from ActivityDesigner. The ActivityDesigner provides a simple designer which lets the user visually design activities in the design mode.

ActivityDesigner provides a simple mechanism for the activities so they can participate in rendering the workflow on the design surface.

ActivityDesigner lets the user customize layout and drawing associated with the activity.

ActivityDesigner lets the user extend the metadata associated with the activity.

The following example shows a complete implementation of an ActivityDesigner for a custom activity. The designer has a flag that can be toggled to allow the base class ActivityDesigner to control the painting or to utilize the various methods the ActivityDesignerPaint class to draw the activity.

[ActivityDesignerTheme(typeof(CustomCompositeActivityDesignerTheme))]
public class CustomActivityDesigner : ActivityDesigner
{
    public override bool CanBeParentedTo(CompositeActivityDesigner parentActivityDesigner)
    {
        if (parentActivityDesigner.GetType().ToString() == "System.Workflow.Activities.IfElseBranchDesigner")
            return false;

        return true;
    }

    private ActivityDesignerVerbCollection verbs = null;

    protected override ActivityDesignerVerbCollection Verbs
    {
        get
        {
            if (this.verbs == null)
                CreateActivityVerbs();

            return this.verbs;
        }
    }

    private void CreateActivityVerbs()
    {
        this.verbs = new ActivityDesignerVerbCollection();
        
        ActivityDesignerVerb addBranchVerb = new ActivityDesignerVerb(this,
            DesignerVerbGroup.View, "Add New Parallel Branch", new EventHandler(OnAddParallelBranch));
        this.verbs.Clear();

        this.verbs.Add(addBranchVerb);
    }

    protected void OnAddParallelBranch(object sender, EventArgs e)
    {
         // Code for adding a new branch to the parallel activity goes here
    }

    protected override Rectangle ImageRectangle
    {
        get 
        {
            Rectangle bounds = this.Bounds;
            Size sz = new Size(24, 24);

            Rectangle imageRect = new Rectangle();
            imageRect.X = bounds.Left + ((bounds.Width - sz.Width) / 2);
            imageRect.Y = bounds.Top + 4;
            imageRect.Size = sz;

            return imageRect;
        }
    }

    protected override Rectangle TextRectangle
    {
        get 
        {
            return new Rectangle(
                this.Bounds.Left + 2, 
                this.ImageRectangle.Bottom,
                this.Bounds.Width - 4, 
                this.Bounds.Height - this.ImageRectangle.Height - 1); 
        }
    }

    protected override void Initialize(Activity activity)
    {
        base.Initialize(activity);
        Bitmap bmp = Properties.Resources.ToolboxImage;
        bmp.MakeTransparent();
        this.Image = bmp;
    }

    readonly static Size BaseSize = new Size(64, 64);
    protected override Size OnLayoutSize(ActivityDesignerLayoutEventArgs e)
    {
        return BaseSize;
    }

    private bool expanded = true;
    private bool useBasePaint = false;

    public bool UseBasePaint
    {
        get { return this.useBasePaint; }
        set { this.useBasePaint = value; }
    }

    public bool Expanded
    {
        get { return this.expanded; }
        set { this.expanded = value; }
    }

    protected override void OnPaint(ActivityDesignerPaintEventArgs e)
    {
        if (this.UseBasePaint == true)
        {
            base.OnPaint(e);
            return;
        }

        DrawCustomActivity(e);
    }

    private void DrawCustomActivity(ActivityDesignerPaintEventArgs e)
    {
        Graphics graphics = e.Graphics;

        CompositeDesignerTheme compositeDesignerTheme = (CompositeDesignerTheme)e.DesignerTheme;

        ActivityDesignerPaint.DrawRoundedRectangle(graphics, compositeDesignerTheme.BorderPen, this.Bounds, compositeDesignerTheme.BorderWidth);

        string text = this.Text;
        Rectangle textRectangle = this.TextRectangle;
        if (!String.IsNullOrEmpty(text) && !textRectangle.IsEmpty)
        {
            ActivityDesignerPaint.DrawText(graphics, compositeDesignerTheme.Font, text, textRectangle, StringAlignment.Center, e.AmbientTheme.TextQuality, compositeDesignerTheme.ForegroundBrush);
        }

        System.Drawing.Image image = this.Image;
        Rectangle imageRectangle = this.ImageRectangle;
        if (image != null && !imageRectangle.IsEmpty)
        {
            ActivityDesignerPaint.DrawImage(graphics, image, imageRectangle, DesignerContentAlignment.Fill);
        }

        ActivityDesignerPaint.DrawExpandButton(graphics,
            new Rectangle(this.Location.X, this.Location.Y, 10, 10),
            this.Expanded,
            compositeDesignerTheme);
    }
}

System.Object
  System.Workflow.ComponentModel.Design.ActivityDesigner
     System.Workflow.ComponentModel.Design.CompositeActivityDesigner

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2015 Microsoft