コード例 #1
0
        private protected Color PaintButtonFaceColor(bool lockhighlight = false, bool disablehoverhighlight = false)
        {
            Color colBack;

            if (Enabled == false)
            {
                colBack = ButtonFaceColour.Multiply(BackDisabledScaling);
            }
            else if (MouseButtonsDown == GLMouseEventArgs.MouseButtons.Left)
            {
                colBack = MouseDownColor;
            }
            else if (lockhighlight || (Hover && !disablehoverhighlight))
            {
                colBack = MouseOverColor;
            }
            else
            {
                colBack = ButtonFaceColour;
            }

            return(colBack);
        }
コード例 #2
0
        /// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/>
        protected override void Paint(Graphics gr)
        {
            Rectangle butarea = ClientRectangle;

            GLMenuStrip p   = Parent as GLMenuStrip;
            bool        ica = IconAreaEnable && p != null;

            if (ica)
            {
                butarea.Width -= p.IconAreaWidth;
                butarea.X     += p.IconAreaWidth;
            }

            if (Enabled && (Highlighted || (Hover && !DisableHoverHighlight)))
            {
                base.PaintButtonFace(ClientRectangle, gr, MouseOverColor);
            }
            else
            {
                if (ica)
                {
                    using (Brush br = new SolidBrush(p.IconStripBackColor))
                    {
                        gr.FillRectangle(br, new Rectangle(0, 0, p.IconAreaWidth, ClientHeight));
                    }
                }

                base.PaintButtonFace(butarea, gr, Enabled ? ButtonFaceColour : ButtonFaceColour.Multiply(BackDisabledScaling));
            }

            //using (Brush inner = new SolidBrush(Color.Red))  gr.FillRectangle(inner, butarea);      // Debug

            base.PaintButtonTextImageFocus(butarea, gr, false);       // don't paint the image

            if (ica)
            {
                int       reduce   = (int)(p.IconAreaWidth * TickBoxReductionRatio);
                Rectangle tickarea = new Rectangle((p.IconAreaWidth - reduce) / 2, (ClientHeight - reduce) / 2, reduce, reduce);

                if (CheckState != CheckStateType.Unchecked)
                {
                    float discaling = Enabled ? 1.0f : BackDisabledScaling;

                    Color checkboxbordercolour = CheckBoxBorderColor.Multiply(discaling); //(Enabled && Hover) ? MouseOverBackColor :
                    Color backcolour           = (Enabled && Hover) ? MouseOverColor : ButtonFaceColour.Multiply(discaling);

                    using (Brush inner = new System.Drawing.Drawing2D.LinearGradientBrush(tickarea, CheckBoxInnerColor.Multiply(discaling), backcolour, 225))
                        gr.FillRectangle(inner, tickarea);            // fill slightly over size to make sure all pixels are painted

                    using (Pen outer = new Pen(checkboxbordercolour)) // paint over to ensure good boundary
                        gr.DrawRectangle(outer, tickarea);
                }

                tickarea.Inflate(-1, -1); // reduce it around the drawn box above

                if (Image != null)        // if we have an image, draw it into the tick area
                {
                    base.DrawImage(Image, tickarea, gr, (Enabled) ? drawnImageAttributesEnabled : drawnImageAttributesDisabled);
                }
                else
                {
                    base.DrawTick(tickarea, Color.FromArgb(200, CheckColor.Multiply(Enabled ? 1.0F : ForeDisabledScaling)), CheckState, gr);
                }
            }
        }
コード例 #3
0
        /// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/>
        protected override void Paint(Graphics gr)
        {
            bool  hasimages      = Image != null;
            float backdisscaling = Enabled ? 1.0f : BackDisabledScaling;
            float foredisscaling = Enabled ? 1.0f : ForeDisabledScaling;

            if (Appearance == CheckBoxAppearance.Button)
            {
                if (Enabled)
                {
                    Rectangle marea = ClientRectangle;
                    marea.Inflate(-2, -2);

                    if (Hover)
                    {
                        using (var b = new LinearGradientBrush(marea, MouseOverColor, MouseOverColor.Multiply(FaceColorScaling), 90))
                            gr.FillRectangle(b, marea);
                    }
                    else if (CheckState == CheckStateType.Checked)
                    {
                        using (var b = new LinearGradientBrush(marea, ButtonFaceColour, ButtonFaceColour.Multiply(FaceColorScaling), 90))
                            gr.FillRectangle(b, marea);
                    }
                }

                if (hasimages)
                {
                    DrawImage(ClientRectangle, gr);
                }

                if (Text.HasChars())
                {
                    using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign))
                        DrawText(ClientRectangle, gr, fmt);
                }
            }
            else if (Appearance == CheckBoxAppearance.Normal)
            {
                Rectangle tickarea = ClientRectangle;
                Rectangle textarea = ClientRectangle;

                int reduce = (int)(tickarea.Height * TickBoxReductionRatio);
                tickarea.Y     += (tickarea.Height - reduce) / 2;
                tickarea.Height = tickarea.Width = reduce;

                if (CheckAlign == ContentAlignment.MiddleRight)
                {
                    tickarea.X      = ClientWidth - tickarea.Width;
                    textarea.Width -= tickarea.Width;
                }
                else
                {
                    textarea.X     += tickarea.Width;
                    textarea.Width -= tickarea.Width;
                }

                if (!Text.HasChars() && ShowFocusBox)       // normally, text has focus box, but if there are none, surround box
                {
                    if (Focused)
                    {
                        using (Pen p1 = new Pen(CheckBoxBorderColor)
                        {
                            DashStyle = DashStyle.Dash
                        })
                        {
                            gr.DrawRectangle(p1, tickarea);
                        }
                    }

                    tickarea.Inflate(-1, -1);
                }

                if (Text.HasChars())
                {
                    using (StringFormat fmt = new StringFormat()
                    {
                        Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.FitBlackBox
                    })
                        DrawText(textarea, gr, fmt);
                }

                if (!hasimages)
                {
                    Color back = !Enabled?CheckBoxInnerColor.Multiply(backdisscaling) : (MouseButtonsDown == GLMouseEventArgs.MouseButtons.Left) ? MouseDownColor : Hover ? MouseOverColor : CheckBoxInnerColor;

                    using (Brush inner = new SolidBrush(back))
                        gr.FillRectangle(inner, tickarea);      // fill slightly over size to make sure all pixels are painted

                    using (Pen outer = new Pen(CheckBoxBorderColor))
                        gr.DrawRectangle(outer, tickarea);

                    tickarea.Inflate(-1, -1);

                    Rectangle checkarea = tickarea;
                    checkarea.Width++; checkarea.Height++;          // convert back to area

                    DrawTick(checkarea, Color.FromArgb(200, CheckColor.Multiply(foredisscaling)), CheckState, gr);
                }
                else
                {
                    DrawImage(tickarea, gr);
                }
            }
            else
            {                                                       // RADIO
                Rectangle tickarea = ClientRectangle;

                tickarea.Height -= 6;
                tickarea.Y      += 2;
                tickarea.Width   = tickarea.Height;

                Rectangle textarea = ClientRectangle;
                textarea.X     += tickarea.Width;
                textarea.Width -= tickarea.Width;

                if (!Text.HasChars() && ShowFocusBox)       // normally, text has focus box, but if there are none, surround box
                {
                    if (Focused)
                    {
                        using (Pen p1 = new Pen(MouseDownColor)
                        {
                            DashStyle = DashStyle.Dash
                        })
                        {
                            gr.DrawRectangle(p1, tickarea);
                        }
                    }

                    tickarea.Inflate(-1, -1);
                }

                if (Text.HasChars())
                {
                    using (StringFormat fmt = new StringFormat()
                    {
                        Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center
                    })
                        DrawText(textarea, gr, fmt);
                }

                if (!hasimages)
                {
                    using (Brush outer = new SolidBrush(CheckBoxBorderColor))
                        gr.FillEllipse(outer, tickarea);

                    tickarea.Inflate(-1, -1);

                    Color back = !Enabled?CheckBoxInnerColor.Multiply(backdisscaling) : (MouseButtonsDown == GLMouseEventArgs.MouseButtons.Left) ? MouseDownColor : Hover ? MouseOverColor : CheckBoxInnerColor;

                    //System.Diagnostics.Debug.WriteLine($"{Name} back {back}");
                    using (Brush second = new SolidBrush(back))
                        gr.FillEllipse(second, tickarea);

                    tickarea.Inflate(-2, -2);

                    if (Checked)
                    {
                        using (Brush second = new SolidBrush(CheckColor.Multiply(foredisscaling)))
                            gr.FillEllipse(second, tickarea);
                    }
                }
                else
                {
                    DrawImage(tickarea, gr);
                }
            }
        }