Hello everyone
I'm facing following problem:
Forms should be able to have different and custom colors for its controls and the form itself.
This seems to work in some cases, but especially for forms using templates like "ListPage" or "DetailsFormMaster" it does not.
Simply setting it in the properties it not an option, as the colors should be persistent throughout multiple forms and I don't want to change it in every form when I want to change the colors.
I've tried doing several things as I'll describe in a moment, but none worked to my satisfaction.
NOTE:
I based most of my Attempts on information I found on the MSDN.
For example, I can't find it right now, but I read that the colorScheme (and/or backgroundColor) attribute are carried to the children if they use the default values, if you simply change them on the biggest container.
Attempt No 1:
Try to find some sort of property or ini file which stores shared property information for multiple objects. (Did not find one)
Attempt No 2:
Define my own class which the targeted forms could then extend from.
Couldn't find the correct class that I should extend from, as EVERY form is defined like this:
public class FormRun extends ObjectRun { }
and I couldn't find anything that would work for me, as extending from ObjectRun didn't work as it resulted in an error (My new class would extend from ObjectRun and the FormRun then would extend from my own, new class).
I did try to extend from the class "Form", which did not result in any errors, but I couldn't override any functions except for "finalize()" I think.
Attempt No 3:
Modify "SysSetupFormRun" to atleast try to change the whole Window Color and try to see if that would work (I found this a lot as people seem to use this to change window colors depending on the current company)
I tried to add this to the "run()" and to the "init()" method, both worked for some windows and dialogs, but forms created from a template still looked mostly the way they always look.
this.design().colorScheme(FormColorScheme::RGB); this.design().backgroundColor(WinAPI::RGB2int(255, 0, 0));
Attempt No 4:
This is my favorite method so far in terms of code design.
I tried to implement my own small class that simply has a function to change the colors of the "design" thing from the form.
I defined an Enum (WindowColor) to make it easier to choose color and created a table to store the RGB-Values.
public static void changeColor(FormRun fr, WindowColor wc) { ColorDef colorDef; // This is my Table for storing the RGB-Values select count(WindowColorId) from colorDef where colorDef.WindowColorId == wc; if(colorDef.WindowColorId > 0) { select colorDef where colorDef.WindowColorId == wc; fr.design().colorScheme(FormColorScheme::RGB); fr.design().backgroundColor(WinAPI::RGB2int(colorDef.R, colorDef.G, colorDef.B)); } else { info(strFmt("%1 is not a valid WindowColor", wc)); } }
I would simply call this function in the init() function of the desired form and it would work in forms that are NOT based of a template.
public void init() { super(); ColorChange::changeColor(this, WindowColor::Warning); }
Attempt No 5:
Iterate through all controls of the form recursively and change all controls of the same class.
This kind of worked, only for specific controls though.
I only tested this on a DetailsFormMaster and the only control it would work on was the TabPages.
If I changed the TabPages though the rest of the form would be complete pitch black and I couldn't find a way around that.
Here's the Function I'd call:
public static void changeControlColor(FormBuildControl fbc, WindowColor wc, int ctrlClassNum) { int handle; int i; FormBuildWindowControl fbwc; if(fbc.isContainer()) { for(i = 1; i <= fbc.controlCount(); i++) { ColorChange::changeControlColor(fbc.controlNum(i), wc, ctrlClassNum); } } handle = fbc.handle(); if(handle == ctrlClassNum) { info(strFmt("%1 == %2", fbc.handle(), ctrlClassNum)); fbwc = fbc; fbwc.colorScheme(FormColorScheme::RGB); fbwc.backgroundColor(WinAPI::RGB2int(255, 0, 0)); } }
int i; for(i = 1; i <= element.form().design().controlCount(); i++) { ColorChange::changeControlColor(element.form().design().controlNum(i), WindowColor::Important, classNum(FormBuildGridControl)); }
--------
Ok I think thats about everything I tried after hours of research.
If I missed anything or you have any questions regarding my Attemps feel free to ask.
I hope anyone here is able to help me.
So please if you know anything about this, whether this doesn't even work or I'm simply trying to do this compeletly wrong, tell me about it.
Also if you could think of anything that maybe doesn't solve this problem exactly but might help me get a similiar result, feel free to tell me about it.
Thank you very much in advance