简体   繁体   English

在Firemonkey TGrid中更改TTextCell的背景

[英]Change background of TTextCell in a Firemonkey TGrid

I'm trying to create a Firemonkey TGrid which will show values with changing background colors depending on the value, but I cannot seem to get the hang of the new Styles thing in firemonkey. 我正在尝试创建一个Firemonkey TGrid,它将根据值显示具有变化的背景色的值,但是我似乎无法理解firemonkey中新样式的内容。

I have followed the advice and structure of Firemonkey Grid Control - Styling a Cell based on a value (via the OnGetValue function call) and created the custom TTextcel derivative, but I still cannot find how to change the background color. 我遵循了Firemonkey网格控件的建议和结构-基于值样式化单元格(通过OnGetValue函数调用)并创建了自定义TTextcel派生类,但是我仍然找不到如何更改背景色。

I tried FindStyleResource('background') as TRectangle but this always returns nil. 我尝试将FindStyleResource('background') as TRectangle但这始终返回nil。

Can anybody get me on the righ track with this? 有人可以让我走上正轨吗?

[Additional Info] [附加信息]
Done what Mike Sutton suggested and it is started to dawn on me ;) The Edit box gave me a Layout-structure, and I'v managed to link that to my TTExtCel control. 完成了Mike Sutton的建议后,它就开始显现出来;)“编辑”框为我提供了“布局”结构,并且设法将其链接到我的TTExtCel控件。 This way I'v been able to change the foreground color through the foreground: BrushObject . 这样,我已经能够通过foreground: BrushObject更改foreground: BrushObject

But the background is done with a TSubImage and a TRectAnimation. 但是背景是通过TSubImage和TRectAnimation完成的。 If I understand correctly, the TSubimage takes a part of Windows7 Style.png and displays this in the Editbox. 如果我理解正确,则TSubimage属于Windows7 Style.png的一部分,并将其显示在Editbox中。 How can I replace the TSubImage with a TRectangle so I can alter the BrushColor? 如何用Tectangle替换TSubImage,以便可以更改BrushColor? The Structure and Properties editor windows don't allow me to add any style elements other then TLayout... 结构和属性编辑器窗口不允许我添加TLayout之外的任何样式元素...

I take it you're using XE3. 我认为您正在使用XE3。 Styles in XE3 use bitmaps for backgrounds, etc so even if you find a 'background' style component it probably won't be a TRectangle (hence why you should avoid such blind casts). XE3中的样式将位图用于背景等,因此即使您找到“背景”样式组件,它也可能不会是TRectangle(因此,应避免盲目转换)。

Pop a TEdit on a form, right click and select Edit Custom Style. 在窗体上弹出一个TEdit,右键单击并选择“编辑自定义样式”。 You will then see what is in the style. 然后,您将看到样式中的内容。 You may be able to modify it to you're needs, or you may have to completely redesign it (maybe to use a custom bitmap, maybe to go back to rectangles). 您可以根据需要对其进行修改,或者必须完全重新设计(可能使用自定义位图,或者返回到矩形)。 You can then set each of your cells StyleLookup properties to use it, or set the styles StyleName to TextCellStyle to have it picked up automatically for every TTextCell. 然后,可以将每个单元格的StyleLookup属性设置为使用它,或将StyleName设置为TextCellStyle以为每个TTextCell自动选择它。

[Additional info] To add an object in the style editor, drag it from the tool palette to the structure pane (top-left of screen). [其他信息]要在样式编辑器中添加对象,请将其从工具面板拖动到结构窗格(屏幕的左上角)。 To start a new element, drop it on the topmost (root) item. 要开始新元素,请将其放在最顶层(根)项目上。 You can then set it's StyleName, then you'll need to Apply and Close double click the Stylebook to get back in the editor and for your changes to take effect (yes, it is that bad). 然后可以将其设置为StyleName,然后需要“应用并关闭”双击Stylebook以返回编辑器,并使您的更改生效(是的,这很糟糕)。

You can the drag/drop stuff in the structure pane to reuse items from the old style. 您可以在结构窗格中拖放内容以重用旧样式中的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM