Question

I would like to add a few coloured square shapes to a form in order to display a legend. Since I haven't come across any way of adding coloured-in shapes, I've resorted to creating the shapes as images, loading them as resources and am currently trying to load them to the form...although this seems like a lengthy workaround for a simple single-coloured square.

First off, is there any way of adding a basic shape of a given colour to an AX form? Otherwise, is there any easier way of adding the image to the form without having to replicate the CompanyImage (or CompanyInfo) form?

NOTE: I'm looking to have the image stored within AX proper and not having the image linked by a filepath to an image on the local machine.

Was it helpful?

Solution

You can draw simple shapes with the WinGDI Class. Here is a simple sample :

void drawShapes()
{
    WinGDI winGDI;
    Int brush, height, width;
    ;

    //myWindow being the FormWindowControl
    height = myWindow.heightValue()/2;
    width  = myWindow.widthValue()/2;

    myWindow.lockDC();

    winGDI  = new WinGDI(myWindow.hDC());

    brush = winGdi.createSolidBrush(WinAPI::RGB2int(0, 0, 255));
    winGDI.fillRect(0, 0, width, height, brush);
    winGDI.deleteObject(brush);

    winGDI.ellipse(0, 0, width, height);

    brush = winGdi.createSolidBrush(WinAPI::RGB2int(255, 0, 0));
    winGDI.fillRect(width, height, 2*width, 2*height, brush);
    winGDI.deleteObject(brush);

    myWindow.UnlockDC();
}

I assume you got something similar.

Now if you just call it once in the form's init, the drawing's will be erased as soon as the paint method of the window control is called (and it's called pretty often).

So the easiest way is to call it in the paint method of the window. This way every time myWindow's content is redrawn, your shapes are too.
You can also force the redrawing of the shapes at a (short) regular time interval like the Tetris Tutorial does (look at the cycle method) using setTimeout but it may be overkill for static content.

You should now have this

Output

OTHER TIPS

You can store images as containers (BLOB) on the database and show them on a form or a report:

How to: Add an Image to a Form

This could be a simple workaround but this what i did for one of my changes. Since you wanted to use it for legend you can just add a button and set the property as flat, give it a color and a text. That should be good enough as a legend.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top