Depending on what you're trying to do it maybe easier to to add a menu to the form. The IsInputKey, KeyDown etc. only fire for the control in focus, meaning if you have lots controls it becomes difficult to manage as you have to subscribe to KeyDown on each one. If a you set the Shortcut property on the MenuItem if the form is active the event associated with the menu item will be fired when the key is pressed.

So generally

- if you want an event for the entire form use a menu item

- if you want an event for a specific control use KeyDown etc.

Cheers,

Rob

By on 1/23/2009 10:45 PM ()

Unfortunately, the KeyPress event is not raised by non-character keys. See [link:msdn.microsoft.com] .

You can, however, subscribe to the KeyDown event which will be raised when non-character keys are depressed.

By on 1/23/2009 4:29 AM ()

thx RayV ,Rob!

Now I know the reason why did I override the IsInputKey but it does not work.

Because:

[UIPermission(SecurityAction.InheritanceDemand, Window=UIPermissionWindow.AllWindows)]

protected virtual bool IsInputKey(Keys keyData)

{

if ((keyData & Keys.Alt) == Keys.Alt)

{

return false;

}

int num = 4;

switch ((keyData & Keys.KeyCode))

{

case Keys.Left:

case Keys.Up:

case Keys.Right:

case Keys.Down:

num = 5;

break;

case Keys.Tab:

num = 6;

break;

}

return (this.IsHandleCreated && ((((int) this.SendMessage(0x87, 0, 0)) & num) != 0));

}

It is not return "true", it is return "Handle"&"Num"

By on 1/26/2009 11:23 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper