четверг, 7 июля 2016 г.

Lookup with possibility to choose color AX 2012

Hi to all!
Recently I've found kind of interesting piece of code, which allows us to choose color for row from Parameters form. You could use this parameter anywhere you want\need.
I just wanted to save this code for myself and then thought "It'd be unfair not to share it".
So, I'm going to share this code with you, hope it'd be helpful for you in your apps!

First of all, we need to create Int control on form with next properties
ColorSheme: RGB
Background color : black
Foreground color : black
Label foreground color (optional) : black
Choose datasourse and datafield if you want save this value in table

Override lookup method for this ds field\control and write next code:

public void lookup(FormControl _formControl, str _filterStr)
{
    Binary customColors;
    int             r, g, b;
    container       chosenColor;
    [r, g, b]   = WinApi::RGBint2Con(MCROrderParameters_CancelledLineColor.backgroundColor());
    chosenColor = WinApi::chooseColor(element.hWnd(), r, g, b, customColors, true);
    if (chosenColor)
    {
        [r, g, b] = chosenColor;
        MCROrderParameters.CancelledLineColor = Winapi::RGB2int(r, g, b);
        MCROrderParameters_CancelledLineColor.backgroundColor(MCROrderParameters.CancelledLineColor);
    }
}

Also, for better UI for user you could also override modified method and write next one:
public void modified()
{       MCROrderParameters_CancelledLineColor.backgroundColor(MCROrderParameters.CancelledLineColor);
for change control color immediately.

That's all probably, hope it helps you sometimes!