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. Image for the cookie policy date

Handling shortcut keys

Hi,

I'm trying to accomplish something simple but I'm a bit overwhelmed by the number of options in this control.

What I want to achieve is handling the save event and do my own stuff. As there is no built-in event to handle Save I did some digging and find the KeyBinder/Commands options.

I tried to create a new ProcessCommand handler like this:
editControl1.Commands["File.Save"].ProcessCommand += += new Syncfusion.Windows.Forms.Edit.ProcessCommandEventHandler(Form1_ProcessCommand);

void Form1_ProcessCommand()
{
MessageBox.Show("Saving");
}

This indeed triggers my custom event but it also triggers the built-in event too.

Help! :) Can you tell me, what I'm wrong?

3 Replies

KN Karikalan Natarajan Syncfusion Team February 22, 2010 02:59 PM UTC

Hi,

Thanks for your patience.

Please refer to the below code with which you can stop the SaveDialog appearance for the Ctrl+S key sequence and make your own Save dialog appear in that place.

[C#]
private void editControl1_KeyDown(object sender, KeyEventArgs e)
{

if (e.Control && (e.KeyCode == Keys.S))
{
this.editControl1.KeyBinder.RemoveBinding(Keys.Control | Keys.S);

MessageBox.Show("Saving");

}
}


The same is given here in a sample. Please try this and let me know if this helps.

Sample : http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=WindowsFormsApplication3-1540662431.zip


Thanks,
Karikalan N


AD Alexander De Man February 23, 2010 03:37 PM UTC

Hi,

While I was awaiting you response, I already implemented the KeyDown method, which does the job. However, this method has one disadvantage and that is that the built-in context menu save option still triggers the save-as dialog (which I don't want).

I noticed that there is an internal Save method, but it isn't allowed to override that in a descendant control (also no save event).

I also tried to remove the old command first and create a new one, but no luck there
editControl1.Commands.Remove("File.Save");
editControl1.Commands.Add("File.Save").ProcessCommand += new ProcessCommandEventHandler(Form1_ProcessCommand);

Is there no other way other than the KeyDown?


KN Karikalan Natarajan Syncfusion Team February 25, 2010 09:31 AM UTC

Hi ,

Thanks for your patience.

There are two solutions for your request.

1) If you want built in context menu which doesn’t contains Save or Save As option, You can clear the Menu items then you can add menu items as your wish. Example code as follows

void editControl1_MenuFill(object sender, EventArgs e)
{
ContextMenuManager cm = (ContextMenuManager)sender;

// To clear default context menu items
cm.ClearMenu();

// Add New Item
cm.AddMenuItem("New",new EventHandler(showNewFile));
cm.AddMenuItem("Open",new EventHandler(showOpenFile));
cm.AddMenuItem("Close",new EventHandler(showCloseFile));

}
2) If you really don’t want context menu, you can set false for this. Example code as follows

this.editControl1.ContextMenuEnabled = false;

Unzip the below link that contains the sample for your reference.

Sample: http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=WindowsFormsApplicationModified-54586243.zip

Thanks,
Karikalan N

Loader.
Live Chat Icon For mobile
Up arrow icon