Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a shortcut key do different things depending on the active tab page?

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?

like image 434
maxfax Avatar asked Jan 23 '26 14:01

maxfax


1 Answers

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;
like image 68
Ian Boyd Avatar answered Jan 26 '26 10:01

Ian Boyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!