user25101622
user25101622

Reputation: 193

How to edit a control within a FireMonkey style outside of the style designer?

In this scenario, I created a default button on my FireMonkey HD application via RADStudio XE2. I then created a custom style for the button, named "Style1". This style is very much similar to the default button style, however, it has a TImage control next to the TText control.

In simple words, a button with an image next to the text.

Now, I'll apply an image to the TImage control for the button? Because if I apply an image to the TImage control VIA the style designer, the other controls who use the style will also get the same image.

Upvotes: 1

Views: 1307

Answers (1)

teran
teran

Reputation: 3234

you can do it at runtime. at first you have to name your TImage style object, for ex. 'btnimg' after that you can find it by name using FindStyleResource:

procedure LoadImage(btn : TButton; imgFileName : string);
var img : TImage;
begin
    img := btn.FindStyleResource('btnimg') as TImage;

    if not assigned(img) then exit;

    img.bitmap.LoadFromFile(imgFileName); 
end;

Upvotes: 3

Related Questions