5

我有一个用于菜单项和 TButton 的 TAction。我希望菜单项显示标签,而 TButton显示图标。但是,当一个 Action 被分配时,Vcl 会自动设置 TButton 的 Caption 属性,我无法摆脱它。

有任何想法吗?

4

3 回答 3

6

在菜单项上,设置ImageIndex-1。在按钮上,将 设置Caption''。您必须在运行时执行此操作。

这将破坏与这些单个属性的操作的关联。该操作仍将用于Hint,OnExecuteOnUpdate

于 2012-12-11T09:02:15.877 回答
4

您可以有两个单独的操作:一个用于菜单项,一个用于按钮。

于 2012-12-11T09:39:36.977 回答
3

一个更hacky的解决方案可能是将TAG 22设置为例如在以下示例中

type

  TButton=Class(Vcl.StdCtrls.TButton)
         procedure SetText(var Message:TWMSETTEXT); message WM_SETTEXT;
  End;

  TForm4 = class(TForm)

    ActionList1: TActionList;
    ImageList1: TImageList;
    Action1: TAction;
    BitBtn1: TBitBtn;
    Button1: TButton;
    Button2: TButton;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

{ TMyButton }

procedure TButton.SetText(var Message:TWMSETTEXT);
begin

  if Tag<>22 then   inherited else Message.Result := 1;
end;
于 2012-12-11T09:33:20.373 回答