Example #1
0
        public override Size GetPreferredSize(Size proposedSize)
        {
            Size preferredSize;

            base.GetPreferredSize(proposedSize);

            using (var g = CreateGraphics())
            {
                proposedSize         = new Size(int.MaxValue, int.MaxValue);
                preferredSize        = TextRenderer.MeasureText(g, Text, WellsMetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), proposedSize, WellsMetroPaint.GetTextFormatFlags(TextAlign));
                preferredSize.Width += 16;
            }

            return(preferredSize);
        }
Example #2
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color borderColor, foreColor;

            if (useCustomForeColor)
            {
                foreColor = ForeColor;

                if (isHovered && !isPressed && Enabled)
                {
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Hover(Theme);
                }
                else if (isHovered && isPressed && Enabled)
                {
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Press(Theme);
                }
                else if (!Enabled)
                {
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Disabled(Theme);
                }
                else
                {
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Normal(Theme);
                }
            }
            else
            {
                if (isHovered && !isPressed && Enabled)
                {
                    foreColor   = WellsMetroPaint.ForeColor.CheckBox.Hover(Theme);
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Hover(Theme);
                }
                else if (isHovered && isPressed && Enabled)
                {
                    foreColor   = WellsMetroPaint.ForeColor.CheckBox.Press(Theme);
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Press(Theme);
                }
                else if (!Enabled)
                {
                    foreColor   = WellsMetroPaint.ForeColor.CheckBox.Disabled(Theme);
                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Disabled(Theme);
                }
                else
                {
                    foreColor = !useStyleColors?WellsMetroPaint.ForeColor.CheckBox.Normal(Theme) : WellsMetroPaint.GetStyleColor(Style);

                    borderColor = WellsMetroPaint.BorderColor.CheckBox.Normal(Theme);
                }
            }

            using (Pen p = new Pen(borderColor))
            {
                Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12);
                e.Graphics.DrawRectangle(p, boxRect);
            }

            if (Checked)
            {
                Color fillColor = CheckState == CheckState.Indeterminate ? borderColor : WellsMetroPaint.GetStyleColor(Style);

                using (SolidBrush b = new SolidBrush(fillColor))
                {
                    Rectangle boxRect = new Rectangle(2, Height / 2 - 4, 9, 9);
                    e.Graphics.FillRectangle(b, boxRect);
                }
            }

            Rectangle textRect = new Rectangle(16, 0, Width - 16, Height);

            TextRenderer.DrawText(e.Graphics, Text, WellsMetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), textRect, foreColor, WellsMetroPaint.GetTextFormatFlags(TextAlign));

            OnCustomPaintForeground(new WellsMetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));

            if (displayFocusRectangle && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }
        }