How to add a shortcut Ctrl+S ?

  • Thread starter Thread starter cyshao
  • Start date Start date
C

cyshao

How to add a shortcut Ctrl+S ?

I want to add a new function for user to provide Ctrl+S to save things.
How can I do that?

Thanks

Charles Shao^_^
 
Create a menu item "Save" under the appropriate mainmenu item such as "File".
In the design-view, click on this "Save" menu item. In the Properties window,
change the value of ShowShortcut to "True". Now, in the same properties
window, click on the property "Shortcut". In the right-side column, a small
button with a down-arrow appears. Click on that button, and from the options
offered, select "CtrlS" option. Now, in the event-handler for the said menu
item, put the neccesary code for the Save functionality. Build your
application. Now, you can use the Ctrl + S keys to directly save your
document.
 
Add the following code to your form to capture Ctrl + S:

private void <your_form>_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.S && e.Control)
MessageBox.Show("Ctrl+S pressed");
}

Gabriel Lozano-Morán
 
Back
Top