I'm designing a device app. Compact Framework 2.0
I want the user to press F1 to navigate to the next screen, but it does not work.
Can't seem to find a solution.
Is it possible?
This is how I normally use Keypress:
This works:
if (e.KeyChar == (char)Keys.M)
{
MessageBox.Show("M pressed");
e.Handled = true;
}
This dos NOT work:
if (e.KeyChar == (char)Keys.F1)
{
MessageBox.Show("F1 pressed");
e.Handled = true;
}
Refer This
You can override the ProcessCmdKey
method of your form class and use keyData == Keys.F1
to check whether F1 is pressed. Above link has example as follows.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.F1)
{
MessageBox.Show("You pressed the F1 key");
return true; // indicate that you handled this keystroke
}
// Call the base class
return base.ProcessCmdKey(ref msg, keyData)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With