2 or more Controls only 1 is considered Active
- by Don
I have 2 controls (MyCtrl) next to each other called ctrlLeft and ctrlRight.
Whenever one receives interaction it is considered active (by default the left one). I override OnDraw and customize the look of the active one a bit.
Currently I have a property Active and an event that I subscribe to from all MyCtrl in there I store a reference to the active one like this:
if (sender is MyCtrl)
{
ctrlActive = (sender as MyCtrl);
ctrlLeft.Active = !(ctrlRight.Active = (ctrlActive == ctrlRight));
}
Either way I need to have ctrlActive as I use it for other things but what I am wondering is if this is the best way make them aware of each other?
Another option I thought of was to store references to every possible MyCtrl and then loop through em all and activate / deactivate the one that match sender just in case I in the future add a ctrlMiddle.
Are my thoughts wrong, is there better options to do this. For example, how does radiobuttons accomplish their similar functionality?