WorkflowDesignerMessageFilter.OnKeyDown(KeyEventArgs) 方法

定义

在按下某个键时发生。

protected:
 virtual bool OnKeyDown(System::Windows::Forms::KeyEventArgs ^ eventArgs);
protected virtual bool OnKeyDown (System.Windows.Forms.KeyEventArgs eventArgs);
abstract member OnKeyDown : System.Windows.Forms.KeyEventArgs -> bool
override this.OnKeyDown : System.Windows.Forms.KeyEventArgs -> bool
Protected Overridable Function OnKeyDown (eventArgs As KeyEventArgs) As Boolean

参数

eventArgs
KeyEventArgs

一个 KeyEventArgs,包含有关事件的信息。

返回

如果消息已处理,则为 true;否则为 false

示例

下面的代码示例演示如何重写 OnKeyDown 方法,以便自定义从工作流设计图面中移除活动的方式。

此代码示例摘自 DesignerShell.cs 文件中的基本设计器宿主 SDK 示例。 有关详细信息,请参阅 Basic Designer Hosting

protected override bool OnKeyDown(KeyEventArgs eventArgs)
{
    if (eventArgs.KeyCode == Keys.Delete)
    {
        ISelectionService selectionService = (ISelectionService)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();
            }
            loader.RemoveActivityFromDesigner(codeActivityComponent);
        }
    }
    return true;
}
Protected Overrides Function OnKeyDown(ByVal eventArgs As KeyEventArgs) As Boolean
    If eventArgs.KeyCode = Keys.Delete Then
        Dim selectionService As ISelectionService = CType(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
            loader.RemoveActivityFromDesigner(codeActivityComponent)
        End If
    End If
    Return True
End Function

注解

在特定对象具有焦点的情况下按下某个键时发生 OnKeyDown

适用于

另请参阅