For this purpose, use the control
System.Windows.Forms.GroupBox
, please see
http://msdn.microsoft.com/en-us/library/system.windows.forms.groupbox.aspx[
^].
During dynamic creation, add all mutually exclusive choices by
RadioButton
as children of the same instance of
GroupBox
using
Control.Controls.Add
or by setting value of the property
Control.Parent
of each
RadioButton
to the same instance of
GroupBox
, see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.aspx[
^].
Doing it dynamically is not harder than what you already done.
[EDIT]
By the way, you could do exact same thing using
Panel
as a container for your radio buttons. The only reason to use an instance of the
GroupBox
is to give a common text label to the group (the property
GroupBox.Text
). You can also use "&" prefix to one character of a label text (as you would do with usual labels (
Label
class); then it will serve as a hot key for a whole group.
—SA