I have two buttons on a control array. I need to detect which button is clicked on which control.
I have the following three controls on Window1:
Container1(0)
Container1(1)
Container1(2)
Each with two buttons.
The easiest way would be to add an ID property to the containers and set it as you desire. There are other ways such as looping through all the controls on the window and trying to find the one that the button is on.
A deeper question is why do you need that information. Might there be a better, more OOP solution?
I was not expecting that it would be that difficult to use buttons on a container control. I was trying to use container controls to simplify the placement of 3 repeated sets of controls.
ContainerControls are intended to encapsulate a set of controls, effectively hiding them from the window itself. Typically, the controls fire events that the container handles, and then the container fires events that are visible to the window. Conversely, the window doesn’t interact directly with the controls in the container. Rather, it calls methods defined on the container, which then can address its internal controls in some manner.
If you added and Event Definition to your container, and raised the event in response to a button press, that event would have the Index of the container as part of the arguments passed to it.