Forms and shortcuts

  • Thread starter Thread starter Sandra
  • Start date Start date
S

Sandra

I need to be able to capture ctrl+L when a user is anywhere in a form as
once this is pressed I need to do something else.

What is the code to capture the ctrl+L keypress?

Thanks in advance

Sandra
 
The important thing is to set the KeyPreview property of the MainForm to
true.

For handling ctrl-L you should use the KeyDown event. The Code in C#:

private void MainForm_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.L)
{
MessageBox.Show("ctrl-L pressed!");
e.Handled = true;
}
}

(Dont't forget to add the KeyDown EventHandler to the MainForm)

The other way might be using menu shortcuts...

Hope this helps,
Andrej
 
Back
Top