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.
Syncfusion Feedback

Handling shortcut keys

Thread ID:

Created:

Updated:

Platform:

Replies:

92985 Feb 17,2010 01:05 PM UTC Feb 25,2010 09:31 AM UTC Windows Forms 3
loading
Tags: EditControl
Alexander De Man
Asked On February 17, 2010 01:05 PM UTC

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?

Karikalan Natarajan [Syncfusion]
Replied On 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

Alexander De Man
Replied On 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?

Karikalan Natarajan [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;