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?
Edit: Thanks for all suggestions.
In my particular case I don't want/need a container as even if I have 3 MyCtrl
only one can still be active and I don't want them to be "linked" 2 and 2 so I went with a public static MyCtrl { get; set; }
that each control can check itself against and I can update it where I need to, which works in my case and rids me of the need to loop through a collection when using multiple MyCtrl
.