当前位置: 首页>>代码示例>>C#>>正文


C# ActivityDesigner类代码示例

本文整理汇总了C#中System.Workflow.ComponentModel.Design.ActivityDesigner的典型用法代码示例。如果您正苦于以下问题:C# ActivityDesigner类的具体用法?C# ActivityDesigner怎么用?C# ActivityDesigner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ActivityDesigner类属于System.Workflow.ComponentModel.Design命名空间,在下文中一共展示了ActivityDesigner类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanBeParentedTo

[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 = 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);
    }
}
开发者ID:.NET开发者,项目名称:System.Workflow.ComponentModel.Design,代码行数:136,代码来源:ActivityDesigner


注:本文中的System.Workflow.ComponentModel.Design.ActivityDesigner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。