Export (0) Print
Expand All
Expand Minimize

WorkflowView.AddDesignerMessageFilter Method

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

public void AddDesignerMessageFilter(
	WorkflowDesignerMessageFilter designerMessageFilter
)

A WorkflowDesignerMessageFilter is a component that handles messages from the WorkflowView.

Using the Strategy design pattern, the WorkflowView will pass messages to the WorkflowDesignerMessageFilter to be handled.

Mouse events, keyboard events, paint and layout events are passed on to a WorkflowDesignerMessageFilter associated with the WorkflowView.

In the following example, a WorkflowDesignerLoader is created and a WorkflowView object is associated with the workflow design surface. In order to retrieve notifications of messages, a WorkflowDesignerMessageFilter is created and added to the WorkflowView object.

This code example is part of the Outlook Workflow Wizard SDK Sample from the WorkflowViewWrapper.cs file. For more information, see Outlook Workflow Wizard Sample.

public WorkflowViewWrapper()
{
    this.loader = new Loader();

    // Create a Workflow Design Surface 
    this.surface = new DesignSurface();
    this.surface.BeginLoad(this.loader);

    // 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.Name = "CustomOutlookWorkflow";

    // Create a Workflow View on the Workflow Design Surface 
    this.workflowView = new WorkflowView(this.surface as IServiceProvider);

    // Add a message filter to the workflow view, to support panning
    MessageFilter filter = new MessageFilter(this.surface as IServiceProvider, this.workflowView);
    this.workflowView.AddDesignerMessageFilter(filter);

    // Activate the Workflow View 
    this.Host.Activate();

    this.workflowView.Dock = DockStyle.Fill;
    this.Controls.Add(workflowView);
    this.Dock = DockStyle.Fill;
}

The MessageFilter object created in the previous code is derived from the WorkflowDesignerMessageFilter class. By overriding the methods of this class, the message filter is notified whenever a user interface event occurs on the WorkflowView object.

internal sealed class MessageFilter : WorkflowDesignerMessageFilter
{
    private bool mouseDown;
    private IServiceProvider serviceProvider;
    private WorkflowView workflowView;

    public MessageFilter(IServiceProvider provider, WorkflowView view)
    {
        this.serviceProvider = provider;
        this.workflowView = view;
    }

    protected override bool OnMouseDown(MouseEventArgs eventArgs)
    {
        // Allow other components to process this event by not returning true. 
        this.mouseDown = true;
        return false;
    }
    protected override bool OnMouseMove(MouseEventArgs eventArgs)
    {
        // Allow other components to process this event by not returning true. 
        if (this.mouseDown)
        {
            this.workflowView.ScrollPosition = new Point(eventArgs.X, eventArgs.Y);
        }
        return false;
    }
    protected override bool OnMouseUp(MouseEventArgs eventArgs)
    {
        // Allow other components to process this event by not returning true. 
        this.mouseDown = false;
        return false;
    }

    protected override bool OnMouseDoubleClick(MouseEventArgs eventArgs)
    {
        this.mouseDown = false;
        return true;
    }

    protected override bool OnMouseEnter(MouseEventArgs eventArgs)
    {
        // Allow other components to process this event by not returning true. 
        this.mouseDown = false;
        return false;
    }

    protected override bool OnMouseHover(MouseEventArgs eventArgs)
    {
        // Allow other components to process this event by not returning true. 
        this.mouseDown = false;
        return false;
    }

    protected override bool OnMouseLeave()
    {
        // Allow other components to process this event by not returning true. 
        this.mouseDown = false;
        return false;
    }

    protected override bool OnMouseWheel(MouseEventArgs eventArgs)
    {
        this.mouseDown = false;
        return true;
    }

    protected override bool OnMouseCaptureChanged()
    {
        // Allow other components to process this event by not returning true. 
        this.mouseDown = false;
        return false;
    }

    protected override bool OnDragEnter(DragEventArgs eventArgs)
    {
        return true;
    }

    protected override bool OnDragOver(DragEventArgs eventArgs)
    {
        return true;
    }

    protected override bool OnDragLeave()
    {
        return true;
    }

    protected override bool OnDragDrop(DragEventArgs eventArgs)
    {
        return true;
    }

    protected override bool OnGiveFeedback(GiveFeedbackEventArgs gfbevent)
    {
        return true;
    }

    protected override bool OnQueryContinueDrag(QueryContinueDragEventArgs qcdevent)
    {
        return true;
    }

    protected override bool OnKeyUp(KeyEventArgs eventArgs)
    {
        return true;
    }

    protected override bool OnShowContextMenu(Point menuPoint)
    {
        return true;
    }

    protected override bool OnKeyDown(KeyEventArgs eventArgs)
    {
        if (eventArgs.KeyCode == Keys.Delete)
        {
            ISelectionService selectionService = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
            if (selectionService != null && selectionService.PrimarySelection is CodeActivity)
            {
                CodeActivity codeActivityComponent = (CodeActivity)selectionService.PrimarySelection;
                CompositeActivity parentActivity = codeActivityComponent.Parent;
                if (parentActivity != null)
                {
                    parentActivity.Activities.Remove(codeActivityComponent);
                    this.ParentView.Update();
                }
            }
        }
        return true;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0
Show:
© 2015 Microsoft