web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Dynamics AX 2012 R3 - change color of forms/controls without hardcoding it

(1) ShareShare
ReportReport
Posted on by

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);
}

I want to note, that I also figured out that in the DetailsFormMaster Template the "Style" property of the "design" node is causing this method to NOT work. If you change the style to "auto" the colorchange will work, but the form will lose some of its functionallity (Especially getting spawned in Edit/View mode depending on how its called)


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));
    }
}
and this is how I called it (in init()):

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

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Alex Kwitny Profile Picture
    395 on at

    You aren't very clear on what your actual question is. If you want colors on all forms, you'll have trouble with ListPages, but if you're looking for an indicator, you should look at adding a bar at the top.

    See this post for a great example:

    daxguy.blogspot.com/.../ax-environment-information-on-ui-simple.html

  • Community Member Profile Picture
    on at

    Thank you for your answer!

    Its a pitty that ListPages don't support coloring.

    The tip with the bar on the top is very great though, thanks alot!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans