Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I determine if an Alt, Shift or Ctrl key is pressed without handling an event?

Use the static property Control.ModifierKeys.

Console.WriteLine(Control.ModifierKeys); 
if ( (Control.ModifierKeys & Keys.Shift) != 0 ) 
  Console.WriteLine("the shift key is down"); 
if ( (Control.ModifierKeys & Keys.Alt) != 0 ) 
  Console.WriteLine("the alt key is down"); 
if ( (Control.ModifierKeys & Keys.Control) != 0 ) 
  Console.WriteLine("the control key is down");

Contributed from George Shepherd's Windows Forms FAQ