private void UncheckRadioButtons(int start, int end, int change) { // Check that the start index is valid if ((start >= 0) && (start < Count)) { do { KryptonContextMenuRadioButton radioButton = this[start] as KryptonContextMenuRadioButton; // Exit as soon as a non-radio button is encountered if (radioButton == null) { break; } // Set the radio button to unchecked if (radioButton.Checked) { radioButton.Checked = false; } // Keep going until we reach the end item if (start == end) { break; } // Moved to next index start += change; } while (true); } }
private void OnRadioButtonCheckedChanged(object sender, EventArgs e) { KryptonContextMenuRadioButton radioButton = sender as KryptonContextMenuRadioButton; // Only interested if the button has become checked if (radioButton.Checked) { // Find the position of this element in the collection int index = IndexOf(radioButton); // Scan upwards for other radio button instances UncheckRadioButtons(index - 1, 0, -1); // Scan downwards for other radio button instances UncheckRadioButtons(index + 1, Count - 1, 1); } }
/// <summary> /// Initialize a new instance of the ViewDrawMenuRadioButton class. /// </summary> /// <param name="provider">Reference to provider.</param> /// <param name="radioButton">Reference to owning radio button entry.</param> public ViewDrawMenuRadioButton(IContextMenuProvider provider, KryptonContextMenuRadioButton radioButton) { _provider = provider; KryptonContextMenuRadioButton = radioButton; // Create fixed storage of the content values _contentValues = new FixedContentValue(radioButton.Text, radioButton.ExtraText, radioButton.Image, radioButton.ImageTransparentColor); // Decide on the enabled state of the display ItemEnabled = provider.ProviderEnabled && KryptonContextMenuRadioButton.Enabled; // Give the heading object the redirector to use when inheriting values KryptonContextMenuRadioButton.SetPaletteRedirect(provider.ProviderRedirector); // Create the content for the actual heading text/image ViewDrawContent = new ViewDrawContent((ItemEnabled ? KryptonContextMenuRadioButton.OverrideNormal : KryptonContextMenuRadioButton.OverrideDisabled), _contentValues, VisualOrientation.Top) { UseMnemonic = true, Enabled = ItemEnabled }; // Create the radio button image drawer and place inside element so it is always centered ViewDrawRadioButton = new ViewDrawRadioButton(KryptonContextMenuRadioButton.StateRadioButtonImages) { CheckState = KryptonContextMenuRadioButton.Checked, Enabled = ItemEnabled }; _layoutCenter = new ViewLayoutCenter { ViewDrawRadioButton }; // Place the radio button on the left of the available space but inside separators _innerDocker = new ViewLayoutDocker { { ViewDrawContent, ViewDockStyle.Fill }, { _layoutCenter, ViewDockStyle.Left }, { new ViewLayoutSeparator(1), ViewDockStyle.Right }, { new ViewLayoutSeparator(3), ViewDockStyle.Left }, { new ViewLayoutSeparator(1), ViewDockStyle.Top }, { new ViewLayoutSeparator(1), ViewDockStyle.Bottom } }; // Use outer docker so that any extra space not needed is used by the null _outerDocker = new ViewLayoutDocker { { _innerDocker, ViewDockStyle.Top }, { new ViewLayoutNull(), ViewDockStyle.Fill } }; // Use context menu specific version of the radio button controller MenuRadioButtonController mrbc = new MenuRadioButtonController(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate); mrbc.Click += OnClick; _innerDocker.MouseController = mrbc; _innerDocker.KeyController = mrbc; // We need to be notified whenever the checked state changes KryptonContextMenuRadioButton.CheckedChanged += OnCheckedChanged; // Add docker as the composite content Add(_outerDocker); }