Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard)
            {
                base.OnPaint(e);
            }
            else
            {
                bool hasimages = Image != null;

                using (Brush br = new SolidBrush(this.BackColor))
                    e.Graphics.FillRectangle(br, ClientRectangle);

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

                        if (mouseover)
                        {
                            using (Brush mover = new SolidBrush(MouseOverColor))
                                e.Graphics.FillRectangle(mover, marea);
                        }
                        else if (CheckState == CheckState.Checked)
                        {
                            using (Brush mover = new SolidBrush(CheckColor))
                                e.Graphics.FillRectangle(mover, marea);
                        }
                    }

                    if (hasimages)
                    {
                        DrawImage(ClientRectangle, e.Graphics);
                    }

                    var txalign = Environment.OSVersion.Platform == PlatformID.Win32NT ? RtlTranslateAlignment(TextAlign) : TextAlign;      // MONO Bug cover over

                    using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(txalign))
                    {
                        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        DrawText(ClientRectangle, e.Graphics, fmt);
                        e.Graphics.SmoothingMode = SmoothingMode.Default;
                    }
                }
                else
                {
                    Rectangle tickarea = ClientRectangle;
                    Rectangle textarea = ClientRectangle;

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

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

                    float discaling = Enabled ? 1.0f : CheckBoxDisabledScaling;

                    Color checkboxbasecolour = (Enabled && mouseover) ? MouseOverColor : CheckBoxColor.Multiply(discaling);

                    if (!hasimages)      // draw the over box of the checkbox if no images
                    {
                        using (Pen outer = new Pen(checkboxbasecolour))
                            e.Graphics.DrawRectangle(outer, tickarea);
                    }

                    tickarea.Inflate(-1, -1);

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

                    //                System.Diagnostics.Debug.WriteLine("Owner draw " + Name + checkarea + rect);

                    if (hasimages)
                    {
                        if (Enabled && mouseover)                // if mouse over, draw a nice box around it
                        {
                            using (Brush mover = new SolidBrush(MouseOverColor))
                            {
                                e.Graphics.FillRectangle(mover, checkarea);
                            }
                        }
                    }
                    else
                    {                                   // in no image, we draw a set of boxes
                        using (Pen second = new Pen(CheckBoxInnerColor.Multiply(discaling), 1F))
                            e.Graphics.DrawRectangle(second, tickarea);

                        tickarea.Inflate(-1, -1);

                        if (FlatStyle == FlatStyle.Flat)
                        {
                            using (Brush inner = new SolidBrush(checkboxbasecolour.Multiply(discaling)))
                                e.Graphics.FillRectangle(inner, tickarea);      // fill slightly over size to make sure all pixels are painted
                        }
                        else
                        {
                            using (Brush inner = new LinearGradientBrush(tickarea, CheckBoxInnerColor.Multiply(discaling), checkboxbasecolour, 225))
                                e.Graphics.FillRectangle(inner, tickarea);      // fill slightly over size to make sure all pixels are painted
                        }

                        using (Pen third = new Pen(checkboxbasecolour.Multiply(discaling), 1F))
                            e.Graphics.DrawRectangle(third, tickarea);
                    }

                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                    using (StringFormat fmt = new StringFormat()
                    {
                        Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.FitBlackBox
                    })
                        DrawText(textarea, e.Graphics, fmt);

                    if (hasimages)
                    {
                        DrawImage(checkarea, e.Graphics);
                    }
                    else
                    {
                        Color c1 = Color.FromArgb(200, CheckColor.Multiply(discaling));
                        if (CheckState == CheckState.Checked)
                        {
                            Point pt1 = new Point(checkarea.X + 2, checkarea.Y + checkarea.Height / 2 - 1);
                            Point pt2 = new Point(checkarea.X + checkarea.Width / 2 - 1, checkarea.Bottom - 2);
                            Point pt3 = new Point(checkarea.X + checkarea.Width - 2, checkarea.Y);

                            using (Pen pcheck = new Pen(c1, 2.0F))
                            {
                                e.Graphics.DrawLine(pcheck, pt1, pt2);
                                e.Graphics.DrawLine(pcheck, pt2, pt3);
                            }
                        }
                        else if (CheckState == CheckState.Indeterminate)
                        {
                            Size cb = new Size(checkarea.Width - 5, checkarea.Height - 5);
                            if (cb.Width > 0 && cb.Height > 0)
                            {
                                using (Brush br = new SolidBrush(c1))
                                {
                                    e.Graphics.FillRectangle(br, new Rectangle(new Point(checkarea.X + 2, checkarea.Y + 2), cb));
                                }
                            }
                        }
                    }

                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
                }
            }
        }
Example #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);
                }
            }
        }
Example #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);
                }
            }
        }