2 or more Controls only 1 is considered Active

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-05-17T21:02:00Z Indexed on 2010/05/18 6:01 UTC
Read the original article Hit count: 197

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms