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.
Unfortunately, activation email could not send to your email. Please try again.

How can I use the KeysBindingDialog to bind a keystroke combination to any standard or custom command?

 

This samples helps you to know, how to bind a keystroke combination to any command.

Please refer to the code snippets below and the sample attached to know 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) Handles menuItem1.Click

editControl1.BindKeyboard()

End Sub

Private Sub editControl1_RegisteringKeyCommands(ByVal sender As Object, ByVal e As System.EventArgs)

Handles editControl1.RegisteringKeyCommands

AddHandler editControl1.Commands.Add("File.SaveCommand").ProcessCommand, AddressOf Command_Save

End sub

Private Sub Command_Save()

editControl1.Save()

End Sub

Private Sub editControl1_RegisteringDefaultKeyBindings(ByVal sender As Object, ByVal e As System.EventArgs)

Handles editControl1.RegisteringDefaultKeyBindings

Me.editControl1.KeyBinder.BindToCommand(Keys.Control Or Keys.S, "File.SaveCommand")

End sub

Article ID: Published Date: Last Revised Date: Platform: Control:
315 04/30/2011 07/10/2014 Windows Forms EditControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.