Is there any framework available for implementing keyboard shortcuts in a .NET2.0 windows application? Also what are the best practices which should be taken care of while doing this?
Is there any framework available for implementing keyboard shortcuts in a .NET2.0 windows application?
Share
Although there’s no obvious way to provide accelerator keys for commands not in menus, it’s not very hard to add these. There are five basic steps:
Define an accelerator enumeration.
Create a hash table to contain the enumerated values.
Create a class to represent accelerator keys.
Load the table with the Keys enumeration.
Finally, override ProcessCmdKey and use a switch statement to dispatch to the right method.
Alternatively, for a slightly more sophisticated approach, you could have the hashtable map to delegates which were the methods you wanted to invoke, as long as they all had the same method signature.
Here’s a short article that outlines the steps above in more detail.