Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can we create shortcut key in gui application like cut,copy,paste,save,save as, bold etc?
Posted
Updated 11-Sep-10 19:48pm
v2

Cut, copy and paste are typically handled for you for basic types.

For the others, they can be implemented in most frameworks with the & notation in menus, in WPF by assigning a gesture or command binding, or in any .NET app by creating a class that derives from IMessageFilter and doing something interesting to it.

IMessageFilter[^]

Or, you can use someone else's code: Shortcut Manager[^]

Cheers.
 
Share this answer
 
v2
Comments
TheyCallMeMrJames 12-Sep-10 0:27am    
fixed the links...
See here[^].
 
Share this answer
 
Create a ToolStripMenuItem to do the job and assign a Shortcut to it. If you don't want a MenuStrip on your Form, put it in a ToolStripContextMenu instead.
 
Share this answer
 
Create a Menu for the application and you will find Shortcut key for each menuItem.

Other than that, you can also handle KeyDown event to write your custom logic around each Shortcut key elements. Check EventArgs for KeyDown.
 
Share this answer
 
If you are using visual studio, open a form and select a gui control that would react to the shortcut. Click on events and choose the keyDown event. A sample code goes like this.

C#
private void headerGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.C)
            {
                // Do something
            }
        }



If you're asking how to implement operations like undo, cut, paste, bold etc. Then, you may choose a richtextbox. It already has default operations with shortcuts but if you want those shortcuts to work even without selecting the control, replace the [// Do something] comment above with richTextBox1.Undo() or something like that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900