首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Microsoft功能区执行命令?

从Microsoft功能区执行命令?
EN

Stack Overflow用户
提问于 2011-06-16 02:49:10
回答 1查看 593关注 0票数 4

多亏了this thread提供的帮助和建议,我已经使用Microsoft Ribbon Framework创建了我的第一个非Delphi Ribbon。

根据A.Bouchez在该线程中发布的guide,我已经设法编译了我的项目,并看到了Microsoft Ribbon的运行情况。

但是,我似乎无法让Ribbon在执行命令时响应输入。

我总是使用TActionManager来管理我的事件,所以我所需要的就是将每个TAction从TActionManager链接到功能区。按照上面链接的教程,我尝试了以下方法,但都无济于事:

代码语言:javascript
复制
// actNew is the name of a TAction set in the TActionManager
procedure TfrmMain.actNewExecute(Sender: TObject);
begin
  ShowMessage('execute new event');
end;

procedure TfrmMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICommand);
begin
  inherited;

  case Command.CommandId of
    cmdNew: // cmdNew was defined in the Ribbon Designer
    begin
      // link the ribbon commands to the TActions
      actNew.OnExecute(Command as TUICommandAction); // obviously will not work
    end;
  end;
end;

那么,如何将我的TActions分配给功能区呢?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-16 06:00:23

通过查看提供的示例,我了解了如何执行这些命令(不知道我是如何错过它们的!)。这些事件似乎必须独立于TActions来定义,所以我想这就是解决之道。

通过在用于调用功能区命令的过程中链接操作OnExecute处理程序是可能的,例如:

代码语言:javascript
复制
private
  CommandNew: TUICommandAction;
  procedure CommandNewExecute(const Args: TUICommandActionEventArgs);

  procedure UpdateRibbonControls;
strict protected
  procedure RibbonLoaded; override;
  procedure CommandCreated(const Sender: TUIRibbon; const Command: TUICommand); override;

implementation

procedure TfrmMain.RibbonLoaded;
begin
  inherited;

  Color:= ColorAdjustLuma(Ribbon.BackgroundColor, -25, False);
  UpdateRibbonControls;
end;

// set command states here
procedure TfrmMain.UpdateRibbonControls;
begin
  if Assigned(CommandNew) then
    CommandNew.Enabled:= True;
end;

// assign the commands
procedure TfrmMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICommand);
begin
  inherited;

  case Command.CommandId of
    cmdNew: // command id defined in the ribbon designer
    begin
      CommandNew:= Command as TUICommandAction;
      CommandNew.OnExecute:= NewExecute;
    end;
  end;
end;

// command events
procedure TfrmMain.NewExecute(const Args: TUICommandActionEventArgs);
begin
  actNew.OnExecute(nil); // < this is calling the event code from a TAction      
end;

Ribbon Framework中的Samples文件夹将更清楚地说明这一点。框架可以在这里找到:http://www.bilsen.com/windowsribbon/index.shtml

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6362734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档