开发者

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

开发者 https://www.devze.com 2023-03-13 16:32 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消