我经过这里张贴我的出发点,例如工作: 更改TTextCell的背景在Firemonkey TGrid
我创建了一个textcellstyle它引用的图像,这是运作良好。 当我运行该程序的所有单元格显示背景画面预期。
从上面的链接,迈克·萨顿(我希望你读这篇文章,我们该怎么办没有你的输入!)写入(重复这里只是为了更容易):
“你可以再设置你的每一个细胞StyleLookup属性来使用它,或者设置的样式样式名到TextCellStyle有它的每TTextCell自动拾取。”
(从约改变字体颜色查询继-个别样式化细胞的Delphi XE4 Firemonkey网格控制 ),可以设置背景颜色动态呢?
我创建了细胞的代码:
Constructor TFinancialCell.Create(AOwner:TComponent);
begin
inherited;
StyleLookup:='textcellstyle';
StyledSettings:=StyledSettings-[TStyledSetting.ssStyle,TStyledSetting.ssFontColor];
TextAlign:=TTextAlign.taTrailing;
end;
这成功地应用于我的图像TFinancialCell。
但是,按照字体颜色查询,我想图像背景只有当达到或任何一个特定的值,显示:
Procedure TFinancialCell.ApplyStyling;
begin
Font.Style:=[TFontStyle.fsItalic];
If IsNegative then
FontColor:=claRed
else
FontColor:=claGreen;
If IsImportant then Font.Style:=[TFontStyle.fsItalic,TFontStyle.fsBold];
If Assigned(Font.OnChanged) then
Font.OnChanged(Font);
Repaint;
end;
任何帮助就如何做到这一点,将不胜感激。
感谢麦克。 我不得不反复折腾了一下,却得到了它根据你的建议的工作。 我添加了一个TRectangle我在stylecontainer textcellstyle,如下所示:
textcellstyle : TLayout
background: TSubImage
rectangle1: TRectangle
rectanimation: TRectAnimation
在TFinancialCell.ApplyStyle我试图FindStyleResource(“背景”),但这总是返回零。 我把它改为FindStyleResource(“rectangle1”),这真是棒极了。 这是因为它看起来对相关styleName属性(这显然默认为“Rectangle1”的矩形1)在Object Inspector? 还是不太只见树木不见木,因为我敢肯定,你可以告诉...
工作代码:
Procedure TFinancialCell.ApplyStyle;
var
T : TFMXObject;
begin
inherited;
T:=FindStyleResource('Rectangle1');
If (T<>nil) and (T is TRectangle) then
begin
If TRectangle(T).Fill<>nil then
begin
If IsNegative then
begin
TRectangle(T).Fill.Color:=claRed;
Repaint;
end;
end;
end;
ApplyStyling;
end;
我也试过,作为一个独立的运动,把上面的代码中TFinancialCell.ApplyStyling,也有工作,所以不知道这是更好的选择,为什么?
我的这些风格的理解总结到目前为止(请纠正/注释必要时):
- 我创建了一个名为textcellstyle的风格,这是我在TFinancialCell.Create适用于我的TFinancialCell类[StyleLookup:=“textcellstyle”]。
- 当我打电话TFinancialCell.ApplyStyling,我能够直接访问TFinancialCell的字体和FONTCOLOR属性,这些属性是TTextCell的性能。
- 如果我要画细胞的背景下,我必须显式调用我手动添加到textcellstyle“风格”的TRectangle组件,然后从那里进入填充等属性。