如何在样式设计器之外的FireMonkey样式中编辑控件? [英] How to edit a control within a FireMonkey style outside of the style designer?

查看:70
本文介绍了如何在样式设计器之外的FireMonkey样式中编辑控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,我通过RADStudio XE2在FireMonkey HD应用程序上创建了一个默认按钮.然后,我为按钮创建了一个自定义样式,名为"Style1".这种样式与默认按钮样式非常相似,但是,在TText控件旁边有一个TImage控件.

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.

简而言之,就是在文字旁边带有图像的按钮.

现在,我将图像应用于按钮的TImage控件吗?因为如果我将图像应用于样式设计器Tstrong控件 VIA ,则其他使用该样式的控件也将获得相同的图像.

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.

推荐答案

您可以在运行时执行此操作. 首先,您必须命名您的TImage样式对象,例如. 'btnimg' 之后,您可以使用FindStyleResource按名称查找它:

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;

这篇关于如何在样式设计器之外的FireMonkey样式中编辑控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆