简体   繁体   中英

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.

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.

I tried FindStyleResource('background') as TRectangle but this always returns 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. This way I'v been able to change the foreground color through the foreground: BrushObject .

But the background is done with a TSubImage and a TRectAnimation. If I understand correctly, the TSubimage takes a part of Windows7 Style.png and displays this in the Editbox. How can I replace the TSubImage with a TRectangle so I can alter the BrushColor? The Structure and Properties editor windows don't allow me to add any style elements other then TLayout...

I take it you're using 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).

Pop a TEdit on a form, right click and select Edit Custom Style. 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.

[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).

You can the drag/drop stuff in the structure pane to reuse items from the old style.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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