如何让快捷键根据活动选项卡页执行不同的操作?

发布于 2024-11-15 17:12:05 字数 397 浏览 8 评论 0原文

我的 TPageControl 上的每个 TTabSheet 上都有一个 TToolBar。每个工具栏都有一个 TToolButton ,它应该响应相同的键盘快捷键。如何提供热键以便为当前页面调用右侧按钮?

在第一个选项卡上, Ctrl+T 应该会发生一些事情,但是切换到第二个选项卡时, Ctrl+T< /kbd> 应该让其他事情发生。

当选项卡显示或隐藏时,是否需要在 asNormalasSuspished 之间切换 TActionList.State

Each TTabSheet on my TPageControl has a TToolBar on it. Each tool bar has a TToolButton that should respond to the same keyboard shortcut. How do I provide hotkeys so that the right button is invoked for the current page?

On the first tab sheet, Ctrl+T should make something happen, but upon switching to the second tab, Ctrl+T should make something else happen instead.

Is this a time to toggle TActionList.State between asNormal and asSuspended when tab sheets are shown or hidden?

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

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

发布评论

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

评论(2

时光瘦了 2024-11-22 17:12:05

如果您希望 Ctrl+T 只是在 PageControl 上的活动 TabSheets 之间切换,则创建一个 操作,使用 Ctrl+T 快捷键,并根据需要在页面之间翻转:

procedure TForm1.actNextPageExecute(Sender: TObject)
var
   nextPageIndex: Integer;
begin
   nextPageIndex := PageControl1.ActivePageIndex+1;

   if (nextPageIndex > PageControl1.Pages.Count-1) then
       nextPageIndex := 0;

   PageControl1.ActivePageIndex := nextPageIndex;
end;

If you want Ctrl+T simply to flip between active TabSheets on a PageControl, then create a single Action, with a Ctrl+T shortcut, and flip between pages as required:

procedure TForm1.actNextPageExecute(Sender: TObject)
var
   nextPageIndex: Integer;
begin
   nextPageIndex := PageControl1.ActivePageIndex+1;

   if (nextPageIndex > PageControl1.Pages.Count-1) then
       nextPageIndex := 0;

   PageControl1.ActivePageIndex := nextPageIndex;
end;
[旋木] 2024-11-22 17:12:05

如果您希望一个 TAction 根据启动它的控件执行不同的操作,只需查看该操作的 ActionComponent 属性即可。将所有控件挂钩到同一操作。

另一种方法是使用相同的快捷方式进行多个操作,并根据可见或聚焦的内容在更新事件中启用或禁用它们。

If you want one TAction to do different things depending on what control initiated it, just look at the action's ActionComponent property. Hook all the controls to the same action.

An alternative would be to have multiple actions with the same shortcut and enable or disable them in the Update event based on what is visible or focused.

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