Using KeyPreview to handle form shortcut keys

If you need to trap shortcut keys in your application to perform misc tasks, use the following code to set KeyPreview to true and then in the KeyDown event handle the actual clicks:

 private void Form_OnLoad(object sender, EventArgs e)
{
KeyPreview
= true;
}

private void form_KeyDown(object sender, KeyEventArgs e)
{

if (e.Alt && e.KeyCode.ToString() == “L”)
{

//DO Something            
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.