开发者

Implementing Centralized Hotkey Handling/Processing

I'm working on a project where I need to implement customizable hotkeys across the application. There are a number of different forms and user controls that need to implement different subsets of hotkeys. I would like to implement all of the handling and processing in a central MessageFilter class.

I want to have a base class that has methods for all hotkeys, and then just override the subset of needed ones in each form/control, but I can't figure out how to have all of the forms and usercontrols share a base class. This would allow me to do something like this to process the hotkeys:

public bool PreFilterMessage(ref Message m)

{

HotKeyAction action = GetActionForKey(keydata);

BaseClass instance = GetBaseClassFromFocusedFormOrCo开发者_如何学运维ntrol();

switch (action)

{

case HotKeyAction.Action1: instance.Action1() break;

}

}

Am I thinking about this the wrong way?


You can create forms as a "base class" so to speak. That is, you could create a Form called ShanesForm with nothing on it. Place your method calls in this form, and then set that form as the base class to all your other forms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜