protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors)
        {
            // check
            //
            if (Control.Checked)
            {
                if (!Control.Enabled && disabledColors)
                {
                    checkColor = SystemColors.ControlDark;
                }

                double scale = GetDpiScaleRatio(e.Graphics);
                using (WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics))
                {
                    using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, 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));
                        wg.FillRectangle(brush, vCross);
                        Rectangle hCross = new Rectangle(layout.checkBounds.X + GetScaledNumber(offset - 1, scale), layout.checkBounds.Y + GetScaledNumber(offset, scale), GetScaledNumber(4, scale), GetScaledNumber(2, scale));
                        wg.FillRectangle(brush, hCross);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // Helper method to overcome the poor GDI ellipse drawing routine
        // VSWhidbey #334097
        private static void DrawAndFillEllipse(WindowsGraphics wg, WindowsPen borderPen, WindowsBrush fieldBrush, Rectangle bounds)
        {
            Debug.Assert(wg != null, "Calling DrawAndFillEllipse with null wg");
            if (wg == null)
            {
                return;
            }

            wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8));
            wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10));
            wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4));

            wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 0), new Point(bounds.X + 8, bounds.Y + 0));
            wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11));

            wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1));
            wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1));

            wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10));
            wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10));

            wg.DrawLine(borderPen, new Point(bounds.X + 0, bounds.Y + 4), new Point(bounds.X + 0, bounds.Y + 8));
            wg.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8));

            wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4));
            wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10));

            wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4));
            wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10));
        }
Ejemplo n.º 3
0
        // used by DataGridViewCheckBoxCell
        internal static void DrawCheckBackground(bool controlEnabled, CheckState controlCheckState, Graphics g, Rectangle bounds, Color checkColor, Color checkBackground, bool disabledColors, ColorData colors)
        {
            using (WindowsGraphics wg = WindowsGraphics.FromGraphics(g)) {
                WindowsBrush brush;
                if (!controlEnabled && disabledColors)
                {
                    brush = new WindowsSolidBrush(wg.DeviceContext, SystemColors.Control);
                }
                else if (controlCheckState == CheckState.Indeterminate && checkBackground == SystemColors.Window && disabledColors)
                {
                    Color comboColor = SystemInformation.HighContrast ? SystemColors.ControlDark :
                                       SystemColors.Control;
                    byte R = (byte)((comboColor.R + SystemColors.Window.R) / 2);
                    byte G = (byte)((comboColor.G + SystemColors.Window.G) / 2);
                    byte B = (byte)((comboColor.B + SystemColors.Window.B) / 2);
                    brush = new WindowsSolidBrush(wg.DeviceContext, Color.FromArgb(R, G, B));
                }
                else
                {
                    brush = new WindowsSolidBrush(wg.DeviceContext, checkBackground);
                }

                try {
                    wg.FillRectangle(brush, bounds);
                }
                finally {
                    if (brush != null)
                    {
                        brush.Dispose();
                    }
                }
            }
        }
 internal static void DrawCheckBackground(bool controlEnabled, CheckState controlCheckState, Graphics g, Rectangle bounds, Color checkColor, Color checkBackground, bool disabledColors, ButtonBaseAdapter.ColorData colors)
 {
     using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(g))
     {
         WindowsBrush brush;
         if (!controlEnabled && disabledColors)
         {
             brush = new WindowsSolidBrush(graphics.DeviceContext, SystemColors.Control);
         }
         else if (((controlCheckState == CheckState.Indeterminate) && (checkBackground == SystemColors.Window)) && disabledColors)
         {
             Color color = SystemInformation.HighContrast ? SystemColors.ControlDark : SystemColors.Control;
             byte  red   = (byte)((color.R + SystemColors.Window.R) / 2);
             byte  green = (byte)((color.G + SystemColors.Window.G) / 2);
             byte  blue  = (byte)((color.B + SystemColors.Window.B) / 2);
             brush = new WindowsSolidBrush(graphics.DeviceContext, Color.FromArgb(red, green, blue));
         }
         else
         {
             brush = new WindowsSolidBrush(graphics.DeviceContext, checkBackground);
         }
         try
         {
             graphics.FillRectangle(brush, bounds);
         }
         finally
         {
             if (brush != null)
             {
                 brush.Dispose();
             }
         }
     }
 }
 private static void DrawAndFillEllipse(WindowsGraphics wg, WindowsPen borderPen, WindowsBrush fieldBrush, Rectangle bounds)
 {
     if (wg != null)
     {
         wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8));
         wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10));
         wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4));
         wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y), new Point(bounds.X + 8, bounds.Y));
         wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11));
         wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1));
         wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1));
         wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10));
         wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10));
         wg.DrawLine(borderPen, new Point(bounds.X, bounds.Y + 4), new Point(bounds.X, bounds.Y + 8));
         wg.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8));
         wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4));
         wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10));
         wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4));
         wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10));
     }
 }
 protected void DrawCheckOnly(PaintEventArgs e, ButtonBaseAdapter.LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors)
 {
     if (this.Control.Checked)
     {
         if (!this.Control.Enabled && disabledColors)
         {
             checkColor = SystemColors.ControlDark;
         }
         float dpiScaleRatio = CheckableControlBaseAdapter.GetDpiScaleRatio(e.Graphics);
         using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics))
         {
             using (WindowsBrush brush = new WindowsSolidBrush(graphics.DeviceContext, checkColor))
             {
                 int       n    = 5;
                 Rectangle rect = new Rectangle(layout.checkBounds.X + GetScaledNumber(n, dpiScaleRatio), layout.checkBounds.Y + GetScaledNumber(n - 1, dpiScaleRatio), GetScaledNumber(2, dpiScaleRatio), GetScaledNumber(4, dpiScaleRatio));
                 graphics.FillRectangle(brush, rect);
                 Rectangle rectangle2 = new Rectangle(layout.checkBounds.X + GetScaledNumber(n - 1, dpiScaleRatio), layout.checkBounds.Y + GetScaledNumber(n, dpiScaleRatio), GetScaledNumber(4, dpiScaleRatio), GetScaledNumber(2, dpiScaleRatio));
                 graphics.FillRectangle(brush, rectangle2);
             }
         }
     }
 }
Ejemplo n.º 7
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 (WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics))
            {
                using (WindowsPen pen = new WindowsPen(wg.DeviceContext, checkBorder))
                {
                    wg.DrawRectangle(pen, bounds);
                }

                // 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 (WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics))
                {
                    using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkBackground))
                    {
                        // Even though we are using GDI here as opposed to GDI+ in Everett, we still need to add 1.
                        bounds.Width++;
                        bounds.Height++;
                        wg.FillRectangle(brush, bounds);
                    }
                }
            }
            DrawCheckOnly(e, layout, colors, checkColor, checkBackground);
        }
        protected void DrawCheckFlat(PaintEventArgs e, ButtonBaseAdapter.LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder, ButtonBaseAdapter.ColorData colors)
        {
            Rectangle checkBounds = layout.checkBounds;

            if (!layout.options.everettButtonCompat)
            {
                checkBounds.Width--;
                checkBounds.Height--;
            }
            using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics))
            {
                using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, checkBorder))
                {
                    graphics.DrawRectangle(pen, checkBounds);
                }
                if (layout.options.everettButtonCompat)
                {
                    checkBounds.Width--;
                    checkBounds.Height--;
                }
                checkBounds.Inflate(-1, -1);
            }
            if (this.Control.CheckState == CheckState.Indeterminate)
            {
                checkBounds.Width++;
                checkBounds.Height++;
                ButtonBaseAdapter.DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, checkBounds);
            }
            else
            {
                using (WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(e.Graphics))
                {
                    using (WindowsBrush brush = new WindowsSolidBrush(graphics2.DeviceContext, checkBackground))
                    {
                        checkBounds.Width++;
                        checkBounds.Height++;
                        graphics2.FillRectangle(brush, checkBounds);
                    }
                }
            }
            this.DrawCheckOnly(e, layout, colors, checkColor, checkBackground, true);
        }