Try this
on form load
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form2_KeyUp);
code behind
private void Form2_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode.In(Keys.F1, Keys.F2, Keys.F3, Keys.F4, Keys.F5, Keys.F6,
Keys.F7, Keys.F8, Keys.F9, Keys.F10, Keys.F11, Keys.F12))
{
MessageBox.Show(string.Format("Function Key {0} is pressed", e.KeyCode));
}
}
in project namespace
public static class Ext
{
public static bool In<t>(this T t, params T[] values)
{
return values.Contains(t);
}
}