将TRAction用于“仅图标”按钮

时间:2012-12-11 08:35:40

标签: delphi c++builder taction

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

有什么想法吗?

3 个答案:

答案 0 :(得分:6)

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

这将打破与仅针对这些个别属性的操作的关联。该操作仍将用于HintOnExecuteOnUpdate

答案 1 :(得分:4)

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

答案 2 :(得分:3)

更苛刻的解决方案可能是将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;