Welcome to MSDN Blogs Sign in | Join | Help

Wriju's BLOG

.NET and everything
Windows Forms – Enable Shortcut Key all over the Form

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!!!

Posted: Wednesday, July 16, 2008 2:09 PM by wriju

Comments

Prashant said:

Hi,

Great piece of information. It works

thanks for the trick

Prashant

# August 1, 2008 9:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker