【问题标题】:Executing Commands from the Microsoft Ribbon?从 Microsoft 功能区执行命令?
【发布时间】:2011-06-16 16:13:32
【问题描述】:

感谢this thread 提供的帮助和建议,我使用 Microsoft Ribbon 框架创建了我的第一个非 Delphi Ribbon。

按照 A.Bouchez 在该线程中发布的 guide,我已成功编译我的项目并查看 Microsoft 功能区的运行情况。

但是,执行命令时,我似乎无法让功能区响应输入。

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

// 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;

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

谢谢。

【问题讨论】:

  • 似乎 Delphi 开发人员是唯一愿意使用 Windows Ribbon Framework 的人。 :)
  • @Ian,我选择使用 Microsoft Ribbon 实现的原因很简单,Delphi TRibbon 看起来或功能都没有那么好。我没有尝试过 TMS 或 DevExpress 组件,但它们看起来也不像 Microsoft 的那样流畅和完整。 Microsoft 功能区的效果非常好。
  • 另一方面,Windows Ribbon Framework 功能区不支持用户的字体首选项(例如 IconTitleFont);也没有任何方法可以手动定义字体。 (注意:如果字体超过 14pt,它会支持字体,但任何更小的字体都不会被功能区支持)。虽然功能区不支持用户的颜色偏好,但您可以为功能区指定主题颜色。

标签: delphi ribbon ribbon-control


【解决方案1】:

我通过查看提供的示例发现了如何执行命令(不知道我是如何错过它们的!)。事件似乎必须独立于 TAction 来定义,所以我想这是要走的路。

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

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;

功能区框架内的 Samples 文件夹将更清楚地展示这一点。该框架可以在这里找到:http://www.bilsen.com/windowsribbon/index.shtml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    相关资源
    最近更新 更多