WorkflowDesignerMessageFilter.OnKeyDown(KeyEventArgs) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when a key is pressed.
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
Parameters
- eventArgs
- KeyEventArgs
A KeyEventArgs that contains information about the event.
Returns
true
if the message is handled; otherwise, false
.
Examples
The following code example shows how to override the OnKeyDown method to customize how to remove activities from a workflow design surface.
This code example is part of the Basic Designer Hosting SDK Sample from the DesignerShell.cs file. For more information, see 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
Remarks
OnKeyDown occurs when a key is pressed when a specific object has focus.