Esempio n. 1
0
        internal override void PaintUp(PaintEventArgs e, CheckState state)
        {
            if (Control.Appearance == Appearance.Button)
            {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintUp(e, Control.CheckState);
            }
            else
            {
                ColorData  colors = PaintPopupRender(e).Calculate();
                LayoutData layout = PaintPopupLayout(show3D: false).Layout();

                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);

                DrawCheckBackground(
                    e,
                    layout.CheckBounds,
                    colors.Options.HighContrast ? colors.ButtonFace : colors.Highlight,
                    disabledColors: true,
                    colors);
                ControlPaint.DrawBorderSimple(
                    e,
                    layout.CheckBounds,
                    (colors.Options.HighContrast && !Control.Enabled) ? colors.WindowFrame : colors.ButtonShadow);
                DrawCheckOnly(e, layout, colors, colors.WindowText);

                AdjustFocusRectangle(layout);
                PaintField(e, layout, colors, colors.WindowText, true);
            }
        }
Esempio n. 2
0
        private void DDB_Draw3DBorder(PaintEventArgs e, Rectangle r, bool raised)
        {
            if (Control.BackColor != SystemColors.Control && SystemInformation.HighContrast)
            {
                if (raised)
                {
                    Color c = ControlPaint.LightLight(Control.BackColor);
                    ControlPaint.DrawBorder(
                        e, r,
                        c, 1, ButtonBorderStyle.Outset,
                        c, 1, ButtonBorderStyle.Outset,
                        c, 2, ButtonBorderStyle.Inset,
                        c, 2, ButtonBorderStyle.Inset);
                }
                else
                {
                    ControlPaint.DrawBorderSimple(e, r, ControlPaint.Dark(Control.BackColor));
                }
            }
            else
            {
                if (raised)
                {
                    Color c = ControlPaint.Light(Control.BackColor);
                    ControlPaint.DrawBorder(
                        e, r,
                        c, 1, ButtonBorderStyle.Solid,
                        c, 1, ButtonBorderStyle.Solid,
                        Control.BackColor, 2, ButtonBorderStyle.Outset,
                        Control.BackColor, 2, ButtonBorderStyle.Outset);

                    Rectangle inside = r;
                    inside.Offset(1, 1);
                    inside.Width  -= 3;
                    inside.Height -= 3;
                    c              = ControlPaint.LightLight(Control.BackColor);
                    ControlPaint.DrawBorder(
                        e, inside,
                        c, 1, ButtonBorderStyle.Solid,
                        c, 1, ButtonBorderStyle.Solid,
                        c, 1, ButtonBorderStyle.None,
                        c, 1, ButtonBorderStyle.None);
                }
                else
                {
                    ControlPaint.DrawBorderSimple(e, r, ControlPaint.Dark(Control.BackColor));
                }
            }
        }
Esempio n. 3
0
        internal override void PaintUp(PaintEventArgs e, CheckState state)
        {
            ColorData  colors = PaintPopupRender(e).Calculate();
            LayoutData layout = PaintPopupLayout(e, state == CheckState.Unchecked, 1).Layout();

            Rectangle r = Control.ClientRectangle;

            if (state == CheckState.Indeterminate)
            {
                using Brush backbrush = CreateDitherBrush(colors.Highlight, colors.ButtonFace);
                PaintButtonBackground(e, r, backbrush);
            }
            else
            {
                Control.PaintBackground(e, r, IsHighContrastHighlighted() ? SystemColors.Highlight : Control.BackColor, r.Location);
            }

            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }

            PaintImage(e, layout);
            PaintField(
                e,
                layout,
                colors,
                state != CheckState.Indeterminate && IsHighContrastHighlighted() ? SystemColors.HighlightText : colors.WindowText,
                drawFocus: true);

            Color borderColor = colors.Options.HighContrast
                ? colors.WindowText
                : GetContrastingBorderColor(colors.ButtonShadow);

            DrawDefaultBorder(e, r, borderColor, Control.IsDefault);

            if (state == CheckState.Unchecked)
            {
                ControlPaint.DrawBorderSimple(e, r, borderColor);
            }
            else
            {
                Draw3DLiteBorder(e, r, colors, false);
            }
        }
        internal override void PaintDown(PaintEventArgs e, CheckState state)
        {
            ColorData  colors = PaintPopupRender(e).Calculate();
            LayoutData layout = PaintPopupLayout(e, false, SystemInformation.HighContrast ? 2 : 1).Layout();

            Rectangle r = Control.ClientRectangle;

            PaintButtonBackground(e, r, null);
            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }
            r.Inflate(-1, -1);

            PaintImage(e, layout);
            PaintField(e, layout, colors, colors.WindowText, true);

            r.Inflate(1, 1);
            DrawDefaultBorder(e, r, colors.Options.HighContrast ? colors.WindowText : colors.WindowFrame, Control.IsDefault);
            ControlPaint.DrawBorderSimple(e, r, colors.Options.HighContrast ? colors.WindowText : colors.ButtonShadow);
        }
Esempio n. 5
0
        internal override void PaintUp(PaintEventArgs e, CheckState state)
        {
            bool hasCustomBorder = Control.FlatAppearance.BorderSize != BorderSize || !Control.FlatAppearance.BorderColor.IsEmpty;

            ColorData  colors = PaintFlatRender(e).Calculate();
            LayoutData layout = PaintFlatLayout(
                up: !Control.FlatAppearance.CheckedBackColor.IsEmpty ||
                (SystemInformation.HighContrast ? state != CheckState.Indeterminate : state == CheckState.Unchecked),
                check: !hasCustomBorder && SystemInformation.HighContrast && state == CheckState.Checked,
                Control.FlatAppearance.BorderSize).Layout();

            // Paint with the BorderColor if set.
            if (!Control.FlatAppearance.BorderColor.IsEmpty)
            {
                colors.WindowFrame = Control.FlatAppearance.BorderColor;
            }

            Rectangle r = Control.ClientRectangle;

            Color backColor = Control.BackColor;

            if (!Control.FlatAppearance.CheckedBackColor.IsEmpty)
            {
                switch (state)
                {
                case CheckState.Checked:
                    backColor = Control.FlatAppearance.CheckedBackColor;
                    break;

                case CheckState.Indeterminate:
                    backColor = Control.FlatAppearance.CheckedBackColor.MixColor(colors.ButtonFace);
                    break;
                }
            }
            else
            {
                switch (state)
                {
                case CheckState.Checked:
                    backColor = colors.Highlight;
                    break;

                case CheckState.Indeterminate:
                    backColor = colors.Highlight.MixColor(colors.ButtonFace);
                    break;
                }
            }

            PaintBackground(e, r, IsHighContrastHighlighted() ? SystemColors.Highlight : backColor);

            if (Control.IsDefault)
            {
                r.Inflate(-1, -1);
            }

            PaintImage(e, layout);
            PaintField(e, layout, colors, IsHighContrastHighlighted() ? SystemColors.HighlightText : colors.WindowText, false);

            if (Control.Focused && Control.ShowFocusCues)
            {
                DrawFlatFocus(e, layout.Focus, colors.Options.HighContrast ? colors.WindowText : colors.ConstrastButtonShadow);
            }

            if (!(Control.IsDefault && Control.Focused && (Control.FlatAppearance.BorderSize == 0)))
            {
                DrawDefaultBorder(e, r, colors.WindowFrame, Control.IsDefault);
            }

            // Always check if the BorderSize is not the default.If not, we need to paint with the BorderSize set by the user.
            if (hasCustomBorder)
            {
                if (Control.FlatAppearance.BorderSize != BorderSize)
                {
                    DrawFlatBorderWithSize(e, r, colors.WindowFrame, Control.FlatAppearance.BorderSize);
                }
                else
                {
                    ControlPaint.DrawBorderSimple(e, r, colors.WindowFrame);
                }
            }
            else if (state == CheckState.Checked && SystemInformation.HighContrast)
            {
                ControlPaint.DrawBorderSimple(e, r, colors.WindowFrame);
                ControlPaint.DrawBorderSimple(e, r, colors.ButtonShadow);
            }
            else if (state == CheckState.Indeterminate)
            {
                Draw3DLiteBorder(e, r, colors, false);
            }
            else
            {
                ControlPaint.DrawBorderSimple(e, r, colors.WindowFrame);
            }
        }
        private void PaintWorker(PaintEventArgs e, bool up, CheckState state)
        {
            up = up && state == CheckState.Unchecked;

            ColorData  colors = PaintRender(e).Calculate();
            LayoutData layout;

            if (Application.RenderWithVisualStyles)
            {
                // Don't have the text-pressed-down effect when we use themed painting to be consistent with Win32.
                layout = PaintLayout(e, true).Layout();
            }
            else
            {
                layout = PaintLayout(e, up).Layout();
            }

            _ = Control as Button;
            if (Application.RenderWithVisualStyles)
            {
                PaintThemedButtonBackground(e, Control.ClientRectangle, up);
            }
            else
            {
                Brush backbrush = null;
                if (state == CheckState.Indeterminate)
                {
                    backbrush = CreateDitherBrush(colors.Highlight, colors.ButtonFace);
                }

                try
                {
                    Rectangle bounds = Control.ClientRectangle;
                    if (up)
                    {
                        // We are going to draw a 2 pixel border
                        bounds.Inflate(-BorderWidth, -BorderWidth);
                    }
                    else
                    {
                        // We are going to draw a 1 pixel border.
                        bounds.Inflate(-1, -1);
                    }

                    PaintButtonBackground(e, bounds, backbrush);
                }
                finally
                {
                    backbrush?.Dispose();
                }
            }

            PaintImage(e, layout);

            // Inflate the focus rectangle to be consistent with the behavior of Win32 app
            if (Application.RenderWithVisualStyles)
            {
                layout.Focus.Inflate(1, 1);
            }

            if (up & IsHighContrastHighlighted())
            {
                Color highlightTextColor = SystemColors.HighlightText;
                PaintField(e, layout, colors, highlightTextColor, false);

                if (Control.Focused && Control.ShowFocusCues)
                {
                    // Drawing focus rectangle of HighlightText color
                    ControlPaint.DrawHighContrastFocusRectangle(e.GraphicsInternal, layout.Focus, highlightTextColor);
                }
            }
            else if (up & IsHighContrastHighlighted())
            {
                PaintField(e, layout, colors, SystemColors.HighlightText, true);
            }
            else
            {
                PaintField(e, layout, colors, colors.WindowText, true);
            }

            if (!Application.RenderWithVisualStyles)
            {
                Rectangle r = Control.ClientRectangle;
                if (Control.IsDefault)
                {
                    r.Inflate(-1, -1);
                }

                DrawDefaultBorder(e, r, colors.WindowFrame, Control.IsDefault);

                if (up)
                {
                    Draw3DBorder(e, r, colors, raised: up);
                }
                else
                {
                    // Not Draw3DBorder(..., raised: false);
                    ControlPaint.DrawBorderSimple(e, r, colors.ButtonShadow);
                }
            }
        }
Esempio n. 7
0
        internal override void PaintOver(PaintEventArgs e, CheckState state)
        {
            if (SystemInformation.HighContrast)
            {
                PaintUp(e, state);
            }
            else
            {
                bool hasCustomBorder = (Control.FlatAppearance.BorderSize != BORDERSIZE || !Control.FlatAppearance.BorderColor.IsEmpty);

                ColorData  colors = PaintFlatRender(e).Calculate();
                LayoutData layout = PaintFlatLayout(
                    up: !Control.FlatAppearance.CheckedBackColor.IsEmpty || state == CheckState.Unchecked,
                    check: false,
                    Control.FlatAppearance.BorderSize).Layout();

                // Paint with the BorderColor if Set.
                if (!Control.FlatAppearance.BorderColor.IsEmpty)
                {
                    colors.windowFrame = Control.FlatAppearance.BorderColor;
                }

                Rectangle r = Control.ClientRectangle;

                Color backColor;
                if (!Control.FlatAppearance.MouseOverBackColor.IsEmpty)
                {
                    backColor = Control.FlatAppearance.MouseOverBackColor;
                }
                else if (!Control.FlatAppearance.CheckedBackColor.IsEmpty)
                {
                    backColor = state == CheckState.Checked || state == CheckState.Indeterminate
                        ? Control.FlatAppearance.CheckedBackColor.MixColor(colors.lowButtonFace)
                        : colors.lowButtonFace;
                }
                else
                {
                    backColor = state == CheckState.Indeterminate
                        ? colors.buttonFace.MixColor(colors.lowButtonFace)
                        : colors.lowButtonFace;
                }

                PaintBackground(e, r, IsHighContrastHighlighted() ? SystemColors.Highlight : backColor);

                if (Control.IsDefault)
                {
                    r.Inflate(-1, -1);
                }

                PaintImage(e, layout);
                PaintField(e, layout, colors, IsHighContrastHighlighted() ? SystemColors.HighlightText : colors.windowText, false);

                if (Control.Focused && Control.ShowFocusCues)
                {
                    DrawFlatFocus(e, layout.focus, colors.constrastButtonShadow);
                }

                if (!(Control.IsDefault && Control.Focused && (Control.FlatAppearance.BorderSize == 0)))
                {
                    DrawDefaultBorder(e, r, colors.windowFrame, Control.IsDefault);
                }

                // Always check if the BorderSize is not the default.If not, we need to paint with the BorderSize set by the user.
                if (hasCustomBorder)
                {
                    if (Control.FlatAppearance.BorderSize != BORDERSIZE)
                    {
                        DrawFlatBorderWithSize(e, r, colors.windowFrame, Control.FlatAppearance.BorderSize);
                    }
                    else
                    {
                        ControlPaint.DrawBorderSimple(e, r, colors.windowFrame);
                    }
                }
                else if (state == CheckState.Unchecked)
                {
                    ControlPaint.DrawBorderSimple(e, r, colors.windowFrame);
                }
                else
                {
                    Draw3DLiteBorder(e, r, colors, false);
                }
            }
        }