Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Changing the color of a TFramedVertScrollBox in FMX --version 2


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Apr 16, 2016 11:18 PM Last Post By: Douglas Rudd
Free Dorfman

Posts: 139
Registered: 2/4/12
Changing the color of a TFramedVertScrollBox in FMX --version 2  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 5:47 PM
--version 2
--
--abstract:
how do I connect ScrollBoxes, Buttons, Labels and such
that I'm creating in code
(Setting size. And font where appropriate)
with Style-stuff
so that I can change things like the background color of the TFramedVertScrollBox?


DX Seattle. FMX.

I have a TFramedVertScrollBox. I simply want to change its "background" color. I haven't really worked with Styles yet.

The mobile app I'm working on is a word puzzle kind of thing. I'm drawing/coloring everything. Think tiles with text on them, buttons and images.

This is my first "real" app written with any Delphi greater than v6. I've been working on this for a while and am fairly close to done. What I have left is:
-IBLite to Android.
-everything to iOS.
-getting the app up to the Play Store & iTunes.
-the final, polished look. this includes:
-----colors
-----fonts
-----bitmaps
I have everything [re-]sizing correctly everywhere: Win, Android phone, Android tablet. Supporting all 4 orientations.

I did some work initially to setup the framework/structure of the app. I am making fairly extensive use of Frames, Rectangles, Buttons and Labels.

The Rectangles have allowed me to color most of what I have. (Every Frame has a client-aligned Rectangle on it which, in turn, contains all the controls for the Frame.)

However: I have (in a few places) a FramedVertScrollBox which I dynamically populate with buttons (based on the underlying data). This works well for me. Until now. When I'm trying to color everything.

What I thought I could do - and still think I probably can - although I'm having a helluva time figuring out how - is to use a StyleBook (or maybe more than one) to change certain aspects of certain controls.

So. Here I am trying to change the "background" color of FramedVertScrollBox and Button controls. Can't I do this by assigning a style to them and modifying some element(s) of that style?

I have been reading and watching tutorials for half the day here and haven't found anything on point. In short, I'm lost.

If you have any thoughts here - either directly - or simply know of a good source of info for me to check out - I would be very grateful.

Shouldn't I be able to change ANY individual aspect of ANY control in this (or some other) fashion?

Many Thanks!

Edited by: Free Dorfman on Apr 15, 2016 7:20 PM
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Changing the color of a TFramedVertScrollBox in FMX --version 2 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 16, 2016 7:34 AM   in response to: Free Dorfman in response to: Free Dorfman
Hello,

I don't 100% get what your're after yet, but if you want to change the
background color of TButtons you can do it like this:

1. right click on a TButton in the designer
2. select "edit custom style", this opens the style designer and
creates a new style for buttons and adds a TStyleBook to your app
3. Look at the structure pane and find out at which place to add a
TRectangle. The TRectangle can be colored as you wish and should
contain the other controls.
4. Disable HitTest of the TRectangle as it will otherwise eat your
mouse clicks and finger taps ;-)
5. Save it and leave the style designer

Greetings

Markus
Free Dorfman

Posts: 139
Registered: 2/4/12
Re: Changing the color of a TFramedVertScrollBox in FMX --version 2 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 16, 2016 9:12 AM   in response to: Markus Humm in response to: Markus Humm
Thanks Markus. I somehow lost the step/idea that I had to add the TRectangle. So now, in a simple, do-nothing app, I have a TVertScrollBox with a colored background.

So now:
(1) Am I correct that I have to change the StyleBook for each Style (WIndows, Android, etc) that I'm going to deploy to?
(2) Am I correct that I cannot create the TStyleBook at runtime ?
(3) Can I at least change the color at runtime ? Something like
StyleBook1.Styles[the-android-one].
  stylecontainer1.box1style1.background.content.rectangle1style.Fill.Color := 
    TAlphaColorRec.Red;


I really need to do this at runtime .

It's bad enough (seemingly) that I have to create the TStyleBook at design time, but I can't see how to change it at runtime.

Any thoughts?

Thanks.
Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: Changing the color of a TFramedVertScrollBox in FMX --version 2 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 16, 2016 11:18 PM   in response to: Free Dorfman in response to: Free Dorfman
You don't have to change the Stylebook to change the color.

Assuming that the rectangle you just added to the VertScrollBox style is named "rectangle1style", this works for me:

procedure TForm47.Button1Click(Sender: TObject);
var MyBackground:TFMXObject;
begin
  MyBackground:=VertScrollbox1.FindStyleResource('rectangle1style');
  if Assigned(MyBackground)and(MyBackground is TRectangle) then
  begin
    TRectangle(MyBackground).Fill.Color:=claRed;
  end;
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02