Вопрос

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