Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Handling multiple keys inside a switch block

I am developing a Windows Forms Application where I am trying to Hide a panel on whenever a user presses the combination of F12 and ctrl key but I am getting the error Operator ‘&&’ cannot be applied to operands of type ‘Keys’ and ‘Keys’ . Thanks for your time.

private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        //method to assign keys
        switch (e.KeyCode)
        {
            case Keys.Down:                   
                SendKeys.Send("{Tab}");
                e.Handled = true;
                break;

            case (Keys.Control && Keys.F12): **// error here** 
                 this.panel3.Hide();
            default:
                break;
        }
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you want to Hide() on Ctrl + F12 combination, you should check e.Modifiers:

...

case (Keys.F12): // On F12
  if (e.Modifiers == Keys.Control) { // On Ctrl + F12
    this.panel3.Hide();
  } 

...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading