Articles in this section
Category / Section

How to use the KeysBindingDialog to bind a keystroke combination to any standard or custom command in WinForms SyntaxEditor (EditorControl)?

1 min read

Bind a keystroke combination

Please refer the below code snippets for how to bind a keystroke combination to any command.

C#

private void menuItem1_Click(object sender, System.EventArgs e)
{
    this.editControl1.BindKeyboard();
}
//Event that is raised when class registers commands for KeyBinding
this.editControl1.RegisteringKeyCommands += new System.EventHandler(this.editControl1_RegisteringKeyCommands);
//Event that is raised when class registers default KeyBinding
this.editControl1.RegisteringDefaultKeyBindings += new
System.EventHandler(this.editControl1_RegisteringDefaultKeyBindings);
// Bind the action name to the action using the RegisteringKeyCommands and ProcessCommandEventHandler events
private void editControl1_RegisteringKeyCommands(object sender, System.EventArgs e)
{
    this.editControl1.Commands.Add( "File.SaveCommand" ).ProcessCommand +=
new ProcessCommandEventHandler( Command_Save );
}
// Bind key combinations to the action name using the RegisteringDefaultKeyBindings event
private void editControl1_RegisteringDefaultKeyBindings(object sender, System.EventArgs e)
{
    this.editControl1.KeyBinder.BindToCommand( Keys.Control | Keys.S, "File.SaveCommand" );
}
// Define the action that needs to be performed
private void Command_Save()
{
    this.editControl1.Save();
}

 

VB

Private Sub menuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     Me.editControl1.BindKeyboard()
End Sub
'Event that is raised when class registers commands for KeyBinding
Private Me.editControl1.RegisteringKeyCommands += New System.EventHandler(AddressOf Me.editControl1_RegisteringKeyCommands)
'Event that is raised when class registers default KeyBinding
Private Me.editControl1.RegisteringDefaultKeyBindings += New System.EventHandler(AddressOf Me.editControl1_RegisteringDefaultKeyBindings)
' Bind the action name to the action using the RegisteringKeyCommands and ProcessCommandEventHandler events
Private Sub editControl1_RegisteringKeyCommands(ByVal sender As Object, ByVal e As System.EventArgs)
     AddHandler editControl1.Commands.Add("File.SaveCommand").ProcessCommand, AddressOf Command_Save
End Sub
' Bind key combinations to the action name using the RegisteringDefaultKeyBindings event
Private Sub editControl1_RegisteringDefaultKeyBindings(ByVal sender As Object, ByVal e As System.EventArgs)
     Me.editControl1.KeyBinder.BindToCommand(Keys.Control Or Keys.S, "File.SaveCommand")
End Sub
' Define the action that needs to be performed
Private Sub Command_Save()
     Me.editControl1.Save() 
End Sub

 

Reference link: https://help.syncfusion.com/windowsforms/syntaxeditor/editing#commands

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied