Question

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?

Was it helpful?

Solution

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;

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top