Windows Application and shortcut key are synonyms. People prefer to use shortcut keys for faster activity. Assume you are in a text box and you want to hit F5 to reload the form. You do not want to move your mouse cursor. So what you will be doing is that you will be adding “Key Down” event to the text box. But if you are in a different text box or in a button that will not work. So you will add “Key Down” event to your form.
But you need to enable a property to work it properly and that’s the trick.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F5)
btnRefresh_Click(null, null);
}
But golden trick is, in the property window of the Form make the following changes
KeyPreview = True
Enjoy programming.
Namoskar!!!
PingBack from http://blog.a-foton.ru/2008/07/windows-forms-%e2%80%93-enable-shortcut-key-all-over-the-form/
Hi,
Great piece of information. It works
thanks for the trick
Prashant
Thank u, it is the information i was searching for
i tried d same code
i also set KeyPreview = True
i pressed F5 when d form loaded
but it dint work
please help!!!
thanks in advance
how to put two combition like (ALT+ S)
Cool shortcuts, very useful. Thanks a bunch!!! I found a few move shortcuts here: www.usingcomputers.co.uk/.../useful-windows-shortcuts.php its worth taking a look at combined with this article. Thanks, keep up the good posts!
Patrick
Hmm. good but how to do it with mulitple keys....?