示例#1
0
        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);
            }
        }
示例#2
0
        /// <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;
            _radioButton = 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 && _radioButton.Enabled;

            // Give the heading object the redirector to use when inheriting values
            _radioButton.SetPaletteRedirect(provider.ProviderRedirector);

            // Create the content for the actual heading text/image
            _drawContent = new ViewDrawContent((_itemEnabled ? (IPaletteContent)_radioButton.OverrideNormal : (IPaletteContent)_radioButton.OverrideDisabled),
                                               _contentValues, VisualOrientation.Top);
            _drawContent.UseMnemonic = true;
            _drawContent.Enabled     = _itemEnabled;

            // Create the radio button image drawer and place inside element so it is always centered
            _drawRadioButton            = new ViewDrawRadioButton(_radioButton.StateRadioButtonImages);
            _drawRadioButton.CheckState = _radioButton.Checked;
            _drawRadioButton.Enabled    = _itemEnabled;
            _layoutCenter = new ViewLayoutCenter();
            _layoutCenter.Add(_drawRadioButton);

            // Place the radio button on the left of the available space but inside separators
            _innerDocker = new ViewLayoutDocker();
            _innerDocker.Add(_drawContent, ViewDockStyle.Fill);
            _innerDocker.Add(_layoutCenter, ViewDockStyle.Left);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Right);
            _innerDocker.Add(new ViewLayoutSeparator(3), ViewDockStyle.Left);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Top);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Bottom);

            // Use outer docker so that any extra space not needed is used by the null
            _outerDocker = new ViewLayoutDocker();
            _outerDocker.Add(_innerDocker, ViewDockStyle.Top);
            _outerDocker.Add(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 += new EventHandler(OnClick);
            _innerDocker.MouseController = mrbc;
            _innerDocker.KeyController   = mrbc;

            // We need to be notified whenever the checked state changes
            _radioButton.CheckedChanged += new EventHandler(OnCheckedChanged);

            // Add docker as the composite content
            Add(_outerDocker);
        }
示例#3
0
        /// <summary>
        /// Raises the Removing event.
        /// </summary>
        /// <param name="e">A TypedCollectionEventArgs instance containing event data.</param>
        protected override void OnRemoving(TypedCollectionEventArgs <KryptonContextMenuItemBase> e)
        {
            // Must unhook from the change event to prevent memory leak
            KryptonContextMenuRadioButton radioButton = e.Item as KryptonContextMenuRadioButton;

            if (radioButton != null)
            {
                radioButton.CheckedChanged -= new EventHandler(OnRadioButtonCheckedChanged);
            }

            base.OnRemoving(e);
        }
示例#4
0
        /// <summary>
        /// Raises the Inserted event.
        /// </summary>
        /// <param name="e">A TypedCollectionEventArgs instance containing event data.</param>
        protected override void OnInserted(TypedCollectionEventArgs <KryptonContextMenuItemBase> e)
        {
            base.OnInserted(e);

            // We monitor changes to the checked state of radio buttons
            KryptonContextMenuRadioButton radioButton = e.Item as KryptonContextMenuRadioButton;

            if (radioButton != null)
            {
                radioButton.CheckedChanged += new EventHandler(OnRadioButtonCheckedChanged);
            }
        }
示例#5
0
        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);
            }
        }