public EnumRadioButtonGroup(ControlBase parent) : base(parent)
 {
     if (!typeof(T).IsEnum)
     {
         throw new Exception("T must be an enumerated type!");
     }
     this.Text = typeof(T).Name;
     for (int i = 0; i < Enum.GetValues(typeof(T)).Length; i++)
     {
         string             name = Enum.GetNames(typeof(T))[i];
         LabeledRadioButton lrb  = this.AddOption(name);
         lrb.UserData = Enum.GetValues(typeof(T)).GetValue(i);
     }
 }
        /// <summary>
        /// Adds a new option.
        /// </summary>
        /// <param name="text">Option text.</param>
        /// <param name="optionName">Internal name.</param>
        /// <returns>Newly created control.</returns>
        public virtual LabeledRadioButton AddOption(string text, string optionName)
        {
            LabeledRadioButton lrb = new LabeledRadioButton(this);

            lrb.Name = optionName;
            lrb.Text = text;
            lrb.RadioButton.Checked += OnRadioClicked;
            lrb.Dock   = Pos.Top;
            lrb.Margin = new Margin(0, 0, 0, 1); // 1 bottom
            lrb.KeyboardInputEnabled = false;    // todo: true?
            lrb.IsTabable            = true;

            Invalidate();
            return(lrb);
        }
        /// <summary>
        /// Handler for the option change.
        /// </summary>
        /// <param name="fromPanel">Event source.</param>
        protected virtual void OnRadioClicked(ControlBase fromPanel, EventArgs args)
        {
            RadioButton @checked = fromPanel as RadioButton;

            foreach (LabeledRadioButton rb in Children.OfType <LabeledRadioButton>()) // todo: optimize
            {
                if (rb.RadioButton == @checked)
                {
                    m_Selected = rb;
                }
                else
                {
                    rb.RadioButton.IsChecked = false;
                }
            }

            OnChanged(m_Selected);
        }