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 hdc = new DeviceContextHdcScope(e); 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); }
private void PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds, bool up) { PushButtonState pbState = DetermineState(up); // First handle transparent case if (ButtonRenderer.IsBackgroundPartiallyTransparent(pbState)) { ButtonRenderer.DrawParentBackground(e, bounds, Control); } ButtonRenderer.DrawButtonForHandle( e, Control.ClientRectangle, false, pbState, DpiHelper.IsScalingRequirementMet ? Control.HandleInternal : IntPtr.Zero); // Now overlay the background image or backcolor (the former overrides the latter), leaving a margin. // We hardcode this margin for now since GetThemeMargins returns 0 all the time. // // Changing this because GetThemeMargins simply does not work in some cases. bounds.Inflate(-ButtonBorderSize, -ButtonBorderSize); //only paint if the user said not to use the themed backcolor. if (!Control.UseVisualStyleBackColor) { bool isHighContrastHighlighted = up && IsHighContrastHighlighted(); Color color = isHighContrastHighlighted ? SystemColors.Highlight : Control.BackColor; if (color.HasTransparency()) { using Brush brush = new SolidBrush(color); e.GraphicsInternal.FillRectangle(brush, bounds); } else { using var hdc = new DeviceContextHdcScope(e); hdc.FillRectangle( bounds, isHighContrastHighlighted ? User32.GetSysColorBrush(ColorTranslator.ToOle(color) & 0xFF) : Control.BackColorBrush); } } // This code is mostly taken from the non-themed rendering code path. if (Control.BackgroundImage != null && !DisplayInformation.HighContrast) { ControlPaint.DrawBackgroundImage( e.GraphicsInternal, Control.BackgroundImage, Color.Transparent, Control.BackgroundImageLayout, Control.ClientRectangle, bounds, Control.DisplayRectangle.Location, Control.RightToLeft); } }
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.DotNetOneButtonCompat) { bounds.Width--; bounds.Height--; } using (var hdc = new DeviceContextHdcScope(e)) { using var hpen = new Gdi32.CreatePenScope(checkBorder); hdc.DrawRectangle(bounds, hpen); // Now subtract, since the rest of the code is like Everett. if (layout.Options.DotNetOneButtonCompat) { 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 hdc = new DeviceContextHdcScope(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++; hdc.FillRectangle(bounds, hbrush); } DrawCheckOnly(e, layout, colors, checkColor); }