Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# GUI
How to make Shortcut Key in C# GUI Form. Please give me some example.
Thank you...
Posted 3-Oct-10 23:52pm
Edited 4-Oct-10 3:30am
v2
Comments
sonigaurav1 at 23-Mar-12 13:28pm
   
Can we make shortkut key for java GUI form also?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can see this link ->

 
shortcut key
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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 :
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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
 
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 220
1 ProgramFOX 120
2 Richard MacCutchan 100
3 kbrandwijk 90
4 ChauhanAjay 80
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 22 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100