In AX2012, I have a list of controls and I want to be able to change the color of any form control on a form to highlight it. The controls are stored as Objects, but I can access them using MyFormRun.controlId(_object.name()). I got the controls by recursing on my form’s controls and storing them.
I tried changing the background/foreground color, but that only seems to be supported for some controls, and did not work for me even with redrawing my form. I tried to call setFocus, and that works only for certain controls (eg buttons), but not other controls (eg button group controls). I tried render a box using system.drawing or WinDGI on the form, but I wasn’t able to find the proper rendering window handle for the form.
I also tried searching the AOT Tree Node objects to find the form and then the control I am looking for, hoping I could change the background color that way, but I go stuck along the way.
Here’s what I want: a generic way to dynamically highlight any type of control on any form at runtime. Drawing on top of the control, changing its color, etc. would work fine for me!
Some properties and actions simply doesn’t males sense for all controls. Trying to set a focus to containers (such as button groups) is a good example.
Fair enough, but there should be a way I can draw a box ontop of a field right? Or is AX too locked down to do custom rendering?
Could you explain in detail what you’re trying to achieve and what’s the functional requirement behind that?
I’m making a search bar for labels in AX forms. I want to be able to search all labels in any AX form and then click next, next through them
And what problem do you want solve by drawing something on top of existing controls?
I want to highlight each field while I click next. Just like when you press Ctrl F in your browser
Then just don’t do it by drawing on top of existing controls and you don’t have to investigate and how to implement such drawing.
Which brings me back to my original question: us there a generic way to dynamically highlight any type of control on any form at runtime?
Any type of control is too generic for me. For example, how should it work with grids?
I don’t see any reason why an entire grid couldn’t be highlighted. That said, because a grid does not have a label, it won’t get hit by my search bar.
How about: any control with a label?
So it doesn’t apply to column labels?
(And there are may other types of controls… You see that you first have to define what your requirement means in practice, only then we can talk about how to do it.)
I don’t see why it couldn’t apply to column labels, I am able to search them through my recursive search and they have separatecontrols. If I only highlight the label or the entire field, I don’t care, as long as I can generically highlight something.
I did define my requirement: search all labels on a form and put them in a list (done), and then distinguish them for the user while they iterate through them by clicking “next”. Just like the search bar in Chrome or IE.
I think I see where your confusion with the column labels comes from. The grid doesn’t match the search string because it has no label, but column labels might match it. I do a recursive search on all controls on the form and store everything that matches the search string.
No, my confusion comes from the fact that you talk about highlighting the whole grid in the reply just above my question (look there if you forgot). You can’t implement contradict requirements and I obviously can’t know that you changed your mind until you write it down. You really need an analysis instead of random shooting.
The grid was merely a single example of things you forgot to think about and specify.
Okay, let’s assume for now it is only form controls with labels. Any ideas how I could generically highlight any form control with a label? Things that would satisfy requirements would be: changing the control color, changing the label color, drawing ontop of the control, etc. Anything to distinguish the control from the others would work.
For example, change the color. It’s trivial for controls that you can access by AX API, and requires some GDI hacking for controls that are not. That’s why it’s so important for you to think about what exactly you want for each type of form control.
Can you should me examples of either for a button control?
Here you have AX API:
button1.backgroundColor(WinAPI::RGB2int(255, 255, 0));
If you want to play with GDI, either you will invest your own time or simply don’t do it. It’s an order of magnitude more difficult than using AX APIs, therefore I think you shouldn’t bother at least before you learn the easier way.