Beispiel #1
0
        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton radioButton = sender as RadioButton;

            if (radioButton == null)
            {
                return;
            }

            RadioGroupBox target = radioButton.Parent as RadioGroupBox;

            if (target == null)
            {
                return;
            }

            if (this.m_bDisableChildrenIfUnchecked == true)
            {
                bool bEnabled = this.m_radioButton.Checked;
                foreach (Control control in this.Controls)
                {
                    if (control != this.m_radioButton)
                    {
                        control.Enabled = bEnabled;
                    }
                }
            }

            if (target.Checked == false)
            {
                return;
            }

            Control parentControl = target.Parent;

            if (parentControl == null)
            {
                return;
            }

            foreach (Control childControl in parentControl.Controls)
            {
                if (childControl is RadioGroupBox)
                {
                    if (childControl != this)
                    {
                        (childControl as RadioGroupBox).Checked = false;
                    }
                }
            }

            if (CheckedChanged != null)
            {
                CheckedChanged(sender, e);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Hooks Check callback events of RadioButton objects within the panel to the RadioButtonPanel object.
 /// </summary>
 public void AddCheckEventListeners()
 {
     foreach (Control control in this.Controls)
     {
         RadioButton radioButton = control as RadioButton;
         if (radioButton != null)
         {
             radioButton.CheckedChanged += new EventHandler(radioButton_CheckedChanged);
         }
         else
         {
             RadioGroupBox radioGroupBox = control as RadioGroupBox;
             if (radioGroupBox != null)
             {
                 radioGroupBox.CheckedChanged += new EventHandler(radioGroupBox_CheckedChanged);
             }
         }
     }
 }
Beispiel #3
0
        private void HandleRadioButtonClick(Control clickedControl)
        {
            if (clickedControl == null)
            {
                return;
            }

            if (clickedControl.Parent is RadioGroupBox)
            {
                // If a RadioGroupBox is checked, the sender is the RadioButton,
                // not the RadioGroupBox, but we need the RadioGroupBox object.
                clickedControl = clickedControl.Parent;
            }

            RadioButton clickedRadioButton = clickedControl as RadioButton;

            if (clickedRadioButton != null)
            {
                if (clickedRadioButton.Checked != true)
                {
                    // Only respond to check events that pertain to the control being checked on
                    return;
                }
            }
            else
            {
                RadioGroupBox clickedRadioGroupBox = clickedControl as RadioGroupBox;
                if (clickedRadioGroupBox != null)
                {
                    if (clickedRadioGroupBox.Checked != true)
                    {
                        // Only respond to check events that pertain to the control being checked on
                        return;
                    }
                }
            }

            foreach (Control control in this.Controls)
            {
                if (control != clickedControl)
                {
                    RadioButton radioButton = control as RadioButton;
                    if (radioButton != null)
                    {
                        // Normally .NET and WinForms would take care of this but
                        // we need a mechanism that turns off radio buttons if a
                        // radio group box is checked.
                        if (radioButton.Checked != false)
                        {
                            radioButton.Checked = false;
                        }
                    }
                    else
                    {
                        RadioGroupBox radioGroupBox = control as RadioGroupBox;
                        if (radioGroupBox != null)
                        {
                            radioGroupBox.Checked = false;
                        }
                        else
                        {
                            // Not expected... must be some other kind of control.
                        }
                    }
                }
            }
        }