)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: EditControl |
Published Date: April 30, 2011 |
Last Revised Date: December 13, 2019

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon