Can't I get ProcessCmdKey to work?

My code is:

 using System.Windows.Forms

 class Class1
 {
      protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
      {
           if (keyData == Keys.Up)
           {
                Console.WriteLine("You pressed the Up arrow key");
                return true;
           }

           ...//and other code lines for Keys.Down, Keys.Left, Keys.Right

           return true;
      }
 }

But all I get is the error:

(namespace). (class) .ProcessCmdKey (ref System.Windows.Forms.Message, System.Windows.Forms.Keys): no suitable method to override was found.

And if I turn off

 return true;

for

 return base.ProcessCmdKey (ref msg, keyData);

I get an error message:

'object' does not contain a definition for ProcessCmdKey.

In fact, my ProcessCmdKey text doesn't even turn green in color, but it stays black when I know that it should be green.

Is this something with the version of the .NET Framework that I am using? Anyway, I use Microsoft Visual Studio 2013 to compile and run my codes.

Or is it somehow related to the security level of my class? I work with a public level class

, . , , , . .

+4
1

ProcessCmdKey System.Windows.Forms.Control. , ( ), .

Class1 , ( ).

'object' ProcessCmdKey

. object Class1 (), object ( ) .

Form.ProcessCmdKey MSDN

Control.ProcessCmdKey MSND

+1

All Articles