c# - Are there multiple ways to group radio buttons in Windows Forms? -
i have few radio buttons in form should connected, want 1 of them in separate container group other related inputs. here general look:
is there way group fourth radio button other 3 though in own group box?
fact radio buttons mutually exclusive when within same parent. being said can think of 2 options.
- let them in same parent, handle
paint
event of parent , draw manually giving impression different groups. - you have manually manage mutual exclusion :(
radiobuttons no magic, set checked
property of other radio's false behind scenes.
private list<radiobutton> radiobuttons = new list<radiobutton>(); //populate radios interested, call hookupevents , should work private void hookupevents() { foreach(var radio in radiobuttons) { radio.checkedchanged -= performmutualexclusion; radio.checkedchanged += performmutualexclusion; } } private void performmutualexclusion(object sender, eventargs e) { radio senderradio = (radiobutton)sender; if(!senderradio.checked) { return; } foreach(var radio in radiobuttons) { if(radio == sender || !radio.checked) { continue; } radio.checked = false; } }
Comments
Post a Comment