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); }
internal static Rectangle DrawPopupBorder(Gdi32.HDC hdc, Rectangle r, ColorData colors) { using var high = new Gdi32.CreatePenScope(colors.highlight); using var shadow = new Gdi32.CreatePenScope(colors.buttonShadow); using var face = new Gdi32.CreatePenScope(colors.buttonFace); hdc.DrawLine(high, r.Right - 1, r.Top, r.Right - 1, r.Bottom); hdc.DrawLine(high, r.Left, r.Bottom - 1, r.Right, r.Bottom - 1); hdc.DrawLine(shadow, r.Left, r.Top, r.Left, r.Bottom); hdc.DrawLine(shadow, r.Left, r.Top, r.Right - 1, r.Top); hdc.DrawLine(face, r.Right - 2, r.Top + 1, r.Right - 2, r.Bottom - 1); hdc.DrawLine(face, r.Left + 1, r.Bottom - 2, r.Right - 1, r.Bottom - 2); r.Inflate(-1, -1); return(r); }
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); } }
private static void DrawUnthemedGroupBoxWithText( IDeviceContext deviceContext, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags) { // Calculate text area, and render text inside it Rectangle textBounds = bounds; textBounds.Width -= TextOffset; Size measuredBounds = TextRenderer.MeasureText( deviceContext, groupBoxText, font, new Size(textBounds.Width, textBounds.Height), flags); textBounds.Width = measuredBounds.Width; textBounds.Height = measuredBounds.Height; if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right) { textBounds.X = bounds.Right - textBounds.Width - TextOffset; } else { textBounds.X += TextOffset; } TextRenderer.DrawText(deviceContext, groupBoxText, font, textBounds, textColor, flags); // Pad text area to stop background from touching text if (textBounds.Width > 0) { textBounds.Inflate(2, 0); } int boxTop = bounds.Top + font.Height / 2; using var hdc = new DeviceContextHdcScope(deviceContext); ReadOnlySpan <int> darkLines = stackalloc int[] { bounds.Left, boxTop - 1, bounds.Left, bounds.Height - 2, // Left bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2, // Right bounds.Left, boxTop - 1, textBounds.X - 3, boxTop - 1, // Top-left textBounds.X + textBounds.Width + 2, boxTop - 1, bounds.Width - 2, boxTop - 1, // Top-right bounds.Width - 2, boxTop - 1, bounds.Width - 2, bounds.Height - 2 // Right }; using var hpenDark = new Gdi32.CreatePenScope(SystemColors.ControlDark); hdc.DrawLines(hpenDark, darkLines); ReadOnlySpan <int> lightLines = stackalloc int[] { bounds.Left + 1, boxTop, bounds.Left + 1, bounds.Height - 1, // Left bounds.Left, bounds.Height - 1, bounds.Width, bounds.Height - 1, // Right bounds.Left + 1, boxTop, textBounds.X - 2, boxTop, // Top-left textBounds.X + textBounds.Width + 1, boxTop, bounds.Width - 1, boxTop, // Top-right bounds.Width - 1, boxTop, bounds.Width - 1, bounds.Height - 1 // Right }; using var hpenLight = new Gdi32.CreatePenScope(SystemColors.ControlLight); hdc.DrawLines(hpenLight, lightLines); }