I have a TAction that is used for both a menu item and a TButton. I want the menu item to show the label, and the TButton to show only the icon. However, when an Action is assigned, Vcl automatically sets the TButton's Caption attribute, and I cannot get rid of it.

Any ideas?

有帮助吗?

解决方案

On the menu item, set ImageIndex to -1. On the button, set the Caption to ''. You must do this at runtime.

This will break the association with the action for just those individual properties. The action will still be used for Hint, OnExecute, OnUpdate etc.

其他提示

You could have two separate actions: one for the menu item, one for the button.

A more hacky solution could be setting the TAG 22 to e.g. in following Example

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top