Exemplo n.º 1
0
 protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
 {
     if (currentRenderer != null)
     {
         currentRenderer.DrawMenuItemBackground(e);
     }
     else
     {
         base.OnRenderMenuItemBackground(e);
     }
 }
Exemplo n.º 2
0
        // Let the item paint itself, and then paint the RadioButton
        // where the check mark is displayed, covering the check mark
        // if it is present.
        protected override void OnPaint(PaintEventArgs e)
        {
            // If the client sets the Image property, the selection behavior
            // remains unchanged, but the RadioButton is not displayed and the
            // selection is indicated only by the selection rectangle.
            if (Image != null)
            {
                base.OnPaint(e);
                return;
            }

            // Determine the correct state of the RadioButton.
            RadioButtonState buttonState = RadioButtonState.UncheckedNormal;

            if (Enabled)
            {
                if (mouseDownState)
                {
                    if (Checked)
                    {
                        buttonState = RadioButtonState.CheckedPressed;
                    }
                    else
                    {
                        buttonState = RadioButtonState.UncheckedPressed;
                    }
                }
                else if (mouseHoverState)
                {
                    if (Checked)
                    {
                        buttonState = RadioButtonState.CheckedHot;
                    }
                    else
                    {
                        buttonState = RadioButtonState.UncheckedHot;
                    }
                }
                else if (Checked)
                {
                    buttonState = RadioButtonState.CheckedNormal;
                }
            }
            else if (Checked)
            {
                buttonState = RadioButtonState.CheckedDisabled;
            }
            else
            {
                buttonState = RadioButtonState.UncheckedDisabled;
            }

            // Calculate the rectangle at which to display the RadioButton.
            Size      glyphSize     = RadioButtonRenderer.GetGlyphSize(e.Graphics, buttonState);
            Rectangle contentRect   = this.ContentRectangle;
            Point     imageLocation = contentRect.Location;
            float     scale         = e.Graphics.DpiX / 96f;

            imageLocation.Offset((int)Math.Round(5f * scale, MidpointRounding.AwayFromZero), (contentRect.Height - glyphSize.Height) / 2);

            ToolStripRenderer renderer = Owner?.Renderer;

            if (renderer != null)
            {
                renderer.DrawMenuItemBackground(new ToolStripItemRenderEventArgs(e.Graphics, this));
                int x = (int)(32 * scale);
                e.Graphics.SetClip(new Rectangle(x, contentRect.Y, Math.Max(contentRect.Width - x, 0), contentRect.Height));
                base.OnPaint(e);
                e.Graphics.ResetClip();
            }
            else
            {
                base.OnPaint(e);
            }

            // If the item is selected and the RadioButton paints with partial
            // transparency, such as when theming is enabled, the check mark
            // shows through the RadioButton image. In this case, paint a
            // non-transparent background first to cover the check mark.
            if (Checked && RadioButtonRenderer.IsBackgroundPartiallyTransparent(buttonState))
            {
                e.Graphics.FillEllipse(SystemBrushes.Control, new Rectangle(imageLocation.X, imageLocation.Y, glyphSize.Width - 1, glyphSize.Height - 1));
            }

            RadioButtonRenderer.DrawRadioButton(e.Graphics, imageLocation, buttonState);
        }
Exemplo n.º 3
0
 protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
 {
     ActualRenderer.DrawMenuItemBackground(e);
 }