コード例 #1
0
        protected void DrawCheckFlat(
            PaintEventArgs e,
            LayoutData layout,
            Color checkColor,
            Color checkBackground,
            Color checkBorder,
            ColorData colors)
        {
            Rectangle bounds = layout.checkBounds;

            // Removed subtracting one for Width and Height. In Everett we needed to do this,
            // since we were using GDI+ to draw the border. Now that we are using GDI,
            // we should not do before drawing the border.

            if (!layout.options.everettButtonCompat)
            {
                bounds.Width--;
                bounds.Height--;
            }

            using (var scope = new PaintEventHdcScope(e))
            {
                using var hpen = new Gdi32.CreatePenScope(checkBorder);
                scope.HDC.DrawRectangle(bounds, hpen);

                // Now subtract, since the rest of the code is like Everett.
                if (layout.options.everettButtonCompat)
                {
                    bounds.Width--;
                    bounds.Height--;
                }
                bounds.Inflate(-1, -1);
            }

            if (Control.CheckState == CheckState.Indeterminate)
            {
                bounds.Width++;
                bounds.Height++;
                DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, bounds);
            }
            else
            {
                using var scope  = new PaintEventHdcScope(e);
                using var hbrush = new Gdi32.CreateBrushScope(checkBackground);

                // Even though we are using GDI here as opposed to GDI+ in Everett, we still need to add 1.
                bounds.Width++;
                bounds.Height++;
                scope.HDC.FillRectangle(bounds, hbrush);
            }

            DrawCheckOnly(e, layout, colors, checkColor, checkBackground);
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (Application.RenderWithVisualStyles & useComboBoxTheme)
            {
                ComboBoxState cbState = ComboBoxState.Normal;

                if (base.MouseIsDown)
                {
                    cbState = ComboBoxState.Pressed;
                }
                else if (base.MouseIsOver)
                {
                    cbState = ComboBoxState.Hot;
                }

                Rectangle dropDownButtonRect = new Rectangle(0, 0, Width, Height);
                if (cbState == ComboBoxState.Normal)
                {
                    pevent.Graphics.FillRectangle(SystemBrushes.Window, dropDownButtonRect);
                }

                using (var scope = new PaintEventHdcScope(pevent))
                {
                    ComboBoxRenderer.DrawDropDownButtonForHandle(
                        scope.HDC,
                        dropDownButtonRect,
                        cbState,
                        DpiHelper.IsScalingRequirementMet ? HandleInternal : IntPtr.Zero);
                }

                // Redraw focus cues
                // For consistency with other PropertyGrid buttons, i.e. those opening system dialogs ("..."), that always show visual cues when focused,
                // we need to do the same for this custom button, painted as ComboBox control part (drop-down).
                if (Focused)
                {
                    dropDownButtonRect.Inflate(-1, -1);
                    ControlPaint.DrawFocusRectangle(pevent.Graphics, dropDownButtonRect, ForeColor, BackColor);
                }
            }
        }
コード例 #3
0
        protected void DrawCheckBackgroundFlat(PaintEventArgs e, Rectangle bounds, Color borderColor, Color checkBackground)
        {
            Color field  = checkBackground;
            Color border = borderColor;

            if (!Control.Enabled)
            {
                // if we are not in HighContrast mode OR we opted into the legacy behavior
                if (!SystemInformation.HighContrast)
                {
                    border = ControlPaint.ContrastControlDark;
                }
                // otherwise we are in HighContrast mode
                field = SystemColors.Control;
            }

            double scale = GetDpiScaleRatio();

            using var scope = new PaintEventHdcScope(e);
            Gdi32.HDC hdc = scope.HDC;
            using var borderPen  = new Gdi32.CreatePenScope(border);
            using var fieldBrush = new Gdi32.CreateBrushScope(field);

            // In high DPI mode when we draw ellipse as three rectantles,
            // the quality of ellipse is poor. Draw it directly as ellipse
            if (scale > 1.1)
            {
                bounds.Width--;
                bounds.Height--;
                hdc.DrawAndFillEllipse(borderPen, fieldBrush, bounds);
                bounds.Inflate(-1, -1);
            }
            else
            {
                DrawAndFillEllipse(hdc, borderPen, fieldBrush, bounds);
            }
        }
コード例 #4
0
        protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors)
        {
            if (!Control.Checked)
            {
                return;
            }

            if (!Control.Enabled && disabledColors)
            {
                checkColor = SystemColors.ControlDark;
            }

            double scale = GetDpiScaleRatio();

            using var paintScope = new PaintEventHdcScope(e);
            Gdi32.HDC hdc = paintScope.HDC;
            using var brush = new Gdi32.CreateBrushScope(checkColor);

            // Circle drawing doesn't work at this size
            int offset = 5;

            Rectangle vCross = new Rectangle(
                layout.checkBounds.X + GetScaledNumber(offset, scale),
                layout.checkBounds.Y + GetScaledNumber(offset - 1, scale),
                GetScaledNumber(2, scale),
                GetScaledNumber(4, scale));

            hdc.FillRectangle(vCross, brush);

            Rectangle hCross = new Rectangle(
                layout.checkBounds.X + GetScaledNumber(offset - 1, scale),
                layout.checkBounds.Y + GetScaledNumber(offset, scale),
                GetScaledNumber(4, scale), GetScaledNumber(2, scale));

            hdc.FillRectangle(hCross, brush);
        }
コード例 #5
0
 internal static Rectangle DrawPopupBorder(PaintEventArgs e, Rectangle r, ColorData colors)
 {
     using var hdc = new PaintEventHdcScope(e);
     return(DrawPopupBorder(hdc, r, colors));
 }