Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to make Shortcut Key in C# GUI Form. Please give me some example.
Thank you...
Posted
Updated 4-Oct-10 3:30am
v2
Comments
sonigaurav1 23-Mar-12 13:28pm    
Can we make shortkut key for java GUI form also?

If you really want to create your own shortcuts then u can catch the event when any of the key pressed and you can add corresponding functions with respect to the key pressed.

C#
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.F1)
            {
                //Help function or your own function
            }
            //return base.ProcessCmdKey(ref msg, keyData);

        }


Hope it helps you.
 
Share this answer
 
first of all you need to set the KeyPreview property of your form to true .
then in the keyDown event of your form , you can write sth like this :
C#
if ( e.Alt && e.KeyCode == Keys.H )
{
   MessagbeBox("Alt-H was pressed");
}

you can also use e.Modifiers to check for key combinations with alt-shift or ctrl
 
Share this answer
 
You can see this link ->


shortcut key
 
Share this answer
 
If you mean how do you assign a shortcut key to a menu item, then prefix it with "&" as in "&File" - that will underline the "F" and assign ALT+F as the shortcut key.
If you want this within a form, then it is a two stage process:
1) Assign the TabOrder of the form correctly, so the label associated with each control is immediately before it in the TabOrder. The easiest way to do this is to add each control to the form in the correct order. The other way is to use the TabOrder toolbar button.
2) Prefix the shortcut key of the label with "&" as above.
 
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