WorkflowView.AddDesignerMessageFilter(WorkflowDesignerMessageFilter) Método

Definición

public:
 void AddDesignerMessageFilter(System::Workflow::ComponentModel::Design::WorkflowDesignerMessageFilter ^ designerMessageFilter);
public void AddDesignerMessageFilter (System.Workflow.ComponentModel.Design.WorkflowDesignerMessageFilter designerMessageFilter);
member this.AddDesignerMessageFilter : System.Workflow.ComponentModel.Design.WorkflowDesignerMessageFilter -> unit
Public Sub AddDesignerMessageFilter (designerMessageFilter As WorkflowDesignerMessageFilter)

Parámetros

Ejemplos

En el ejemplo siguiente, WorkflowDesignerLoader se crea y un objeto WorkflowView está asociado a la superficie de diseño de flujo de trabajo.In the following example, a WorkflowDesignerLoader is created and a WorkflowView object is associated with the workflow design surface. Para recuperar notificaciones de mensajes, WorkflowDesignerMessageFilter se crea y agrega al objeto WorkflowView.In order to retrieve notifications of messages, a WorkflowDesignerMessageFilter is created and added to the WorkflowView object.

Este ejemplo de código forma parte del ejemplo SDK del asistente del flujo de trabajo de Outlook del archivo WorkflowViewWrapper.cs.This code example is part of the Outlook Workflow Wizard SDK Sample from the WorkflowViewWrapper.cs file. Para obtener más información, vea ejemplo del Asistente para flujos de trabajo de Outlook.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;
}
Public Sub New()

    Me.loaderValue = New Loader()

    ' Create a Workflow Design Surface
    Me.surface = New DesignSurface()
    Me.surface.BeginLoad(Me.loaderValue)

    ' Get the Workflow Designer Host
    If Me.surface.GetService(GetType(IDesignerHost)) IsNot Nothing AndAlso TypeOf Me.surface.GetService(GetType(IDesignerHost)) Is IDesignerHost Then
        Me.Host = CType(Me.surface.GetService(GetType(IDesignerHost)), IDesignerHost)
    Else
        Return
    End If

    ' Create a Sequential Workflow by using the Workflow Designer Host
    SequentialWorkflow = CType(Host.CreateComponent(GetType(SequentialWorkflowActivity)), SequentialWorkflowActivity)
    SequentialWorkflow.Name = "CustomOutlookWorkflow"

    ' Create a Workflow View on the Workflow Design Surface
    Me.workflowView = New WorkflowView(CType(Me.surface, IServiceProvider))

    ' Add a message filter to the workflow view, to support panning
    Dim filter As MessageFilter = New MessageFilter(CType(Me.surface, IServiceProvider), Me.workflowView)
    Me.workflowView.AddDesignerMessageFilter(filter)

    ' Activate the Workflow View
    Me.Host.Activate()

    Me.workflowView.Dock = DockStyle.Fill
    Me.Controls.Add(workflowView)
    Me.Dock = DockStyle.Fill
End Sub

El objeto MessageFilter creado en el código anterior se deriva de la clase WorkflowDesignerMessageFilter.The MessageFilter object created in the previous code is derived from the WorkflowDesignerMessageFilter class. Invalidando los métodos de esta clase, el filtro de mensajes es notificado cuando ocurre un evento de interfaz de usuario en el objeto WorkflowView.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;
    }
}
Friend Class MessageFilter
    Inherits WorkflowDesignerMessageFilter

    Private mouseDown As Boolean
    Private serviceProvider As IServiceProvider
    Private workflowView As WorkflowView

    Public Sub New(ByVal provider As IServiceProvider, ByVal view As WorkflowView)
        Me.serviceProvider = provider
        Me.workflowView = view
    End Sub

    Protected Overrides Function OnMouseDown(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        ' Allow other components to process this event by not returning true.
        Me.mouseDown = True
        Return False
    End Function
    Protected Overrides Function OnMouseMove(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        ' Allow other components to process this event by not returning true.
        If (Me.mouseDown) Then
            Me.workflowView.ScrollPosition = New Point(eventArgs.X, eventArgs.Y)
        End If
        Return False
    End Function
    Protected Overrides Function OnMouseUp(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        ' Allow other components to process this event by not returning true.
        Me.mouseDown = False
        Return False
    End Function

    Protected Overrides Function OnMouseDoubleClick(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        Me.mouseDown = False
        Return True
    End Function

    Protected Overrides Function OnMouseEnter(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        ' Allow other components to process this event by not returning true.
        Me.mouseDown = False
        Return False
    End Function

    Protected Overrides Function OnMouseHover(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        ' Allow other components to process this event by not returning true.
        Me.mouseDown = False
        Return False
    End Function

    Protected Overrides Function OnMouseLeave() As Boolean
        ' Allow other components to process this event by not returning true.
        Me.mouseDown = False
        Return False
    End Function

    Protected Overrides Function OnMouseWheel(ByVal eventArgs As System.Windows.Forms.MouseEventArgs) As Boolean
        Me.mouseDown = False
        Return True
    End Function

    Protected Overrides Function OnMouseCaptureChanged() As Boolean
        ' Allow other components to process this event by not returning true.
        Me.mouseDown = False
        Return False
    End Function

    Protected Overrides Function OnDragEnter(ByVal eventArgs As System.Windows.Forms.DragEventArgs) As Boolean
        Return True
    End Function

    Protected Overrides Function OnDragOver(ByVal eventArgs As System.Windows.Forms.DragEventArgs) As Boolean
        Return True
    End Function

    Protected Overrides Function OnDragLeave() As Boolean
        Return True
    End Function

    Protected Overrides Function OnDragDrop(ByVal eventArgs As System.Windows.Forms.DragEventArgs) As Boolean
        Return True
    End Function

    Protected Overrides Function OnGiveFeedback(ByVal eventArgs As System.Windows.Forms.GiveFeedbackEventArgs) As Boolean
        Return True
    End Function

    Protected Overrides Function OnQueryContinueDrag(ByVal eventArgs As System.Windows.Forms.QueryContinueDragEventArgs) As Boolean
        Return True
    End Function

    Protected Overrides Function OnKeyUp(ByVal eventArgs As System.Windows.Forms.KeyEventArgs) As Boolean
        Return True
    End Function

    Protected Overrides Function OnShowContextMenu(ByVal screenMenuPoint As System.Drawing.Point) As Boolean
        Return True
    End Function

    Protected Overrides Function OnKeyDown(ByVal eventArgs As System.Windows.Forms.KeyEventArgs) As Boolean
        If eventArgs.KeyCode = Keys.Delete Then
            Dim selectionService As ISelectionService = CType(Me.serviceProvider.GetService(GetType(ISelectionService)), ISelectionService)
            If selectionService IsNot Nothing AndAlso TypeOf selectionService.PrimarySelection Is CodeActivity Then
                Dim codeActivityComponent As CodeActivity = CType(selectionService.PrimarySelection, CodeActivity)
                Dim parentActivity As CompositeActivity = codeActivityComponent.Parent
                If parentActivity IsNot Nothing Then
                    parentActivity.Activities.Remove(codeActivityComponent)
                    Me.ParentView.Update()
                End If
            End If
        End If
        Return True
    End Function
End Class

Comentarios

WorkflowDesignerMessageFilter es un componente que administra los mensajes de WorkflowView.A WorkflowDesignerMessageFilter is a component that handles messages from the WorkflowView.

Con el patrón de diseño Strategy, WorkflowView pasará los mensajes a WorkflowDesignerMessageFilter para ser administrado.Using the Strategy design pattern, the WorkflowView will pass messages to the WorkflowDesignerMessageFilter to be handled.

Los eventos del mouse, eventos de teclado, pintura y eventos de diseño se pasan a un WorkflowDesignerMessageFilter asociado a WorkflowView.Mouse events, keyboard events, paint and layout events are passed on to a WorkflowDesignerMessageFilter associated with the WorkflowView.

Se aplica a