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?

有帮助吗?

解决方案

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;

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top