实施集中热键处理/处理

发布于 2024-08-16 18:55:37 字数 498 浏览 4 评论 0原文

我正在开发一个项目,需要在整个应用程序中实现可自定义的热键。有许多不同的表单和用户控件需要实现不同的热键子集。我想在中央 MessageFilter 类中实现所有处理和处理。

我想要一个具有所有热键方法的基类,然后只需重写每个表单/控件中所需的子集,但我不知道如何让所有表单和用户控件共享一个基类。这将允许我执行类似的操作来处理热键:

public bool PreFilterMessage(ref Message m)
{
HotKeyAction 操作 = GetActionForKey(keydata);
BaseClass 实例 = GetBaseClassFromFocusedFormOrControl();
开关(动作)
{
case HotKeyAction.Action1:instance.Action1() 中断;
}
} 我是否

以错误的方式思考这个问题?

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 = GetBaseClassFromFocusedFormOrControl();
switch (action)
{
case HotKeyAction.Action1: instance.Action1() break;
}
}

Am I thinking about this the wrong way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔芯 2024-08-23 18:55:37

可以这么说,您可以将表单创建为“基类”。也就是说,您可以创建一个名为 ShanesForm 的表单,其中不包含任何内容。将方法调用放置在此表单中,然后将该表单设置为所有其他表单的基类。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文