/// <summary>Paint the backgrounds to show capture groups</summary> private void CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { e.Handled = false; var grid = (DataGridView)sender; if (e.RowIndex < 0 || e.RowIndex >= Pattern.Subs.Count) { return; } switch (grid.Columns[e.ColumnIndex].Name) { case ColumnNames.Tag: e.CellStyle.BackColor = Constants.BkColors[e.RowIndex % Constants.BkColors.Length]; e.CellStyle.SelectionBackColor = Gfx_.Blend(e.CellStyle.BackColor, Color.Black, 0.2f); break; } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); var bounds = ClientRectangle; bounds.Inflate(-1, -1); if (bounds.Width <= 0 || bounds.Height <= 0) { return; } var gfx = e.Graphics; var total = TotalRange; gfx.SmoothingMode = SmoothingMode.AntiAlias; Color c0, c1; Point pt0 = new Point(bounds.Left, 0); Point pt1 = new Point(bounds.Right, 0); // Create rectangles for the highlight ranges foreach (var r in m_indicator_ranges) { int sy = (int)(Math_.Frac(total.Beg, r.Range.Beg, total.End) * bounds.Height); int ey = (int)(Math_.Frac(total.Beg, r.Range.End, total.End) * bounds.Height); r.m_rect = new Rectangle(bounds.X, bounds.Y + sy, bounds.Width, Math.Max(ey - sy, 1)); } // Background c0 = Gfx_.Blend(Color.Black, TrackColor, 0.8f); c1 = TrackColor; using (var bsh = new LinearGradientBrush(pt0, pt1, c0, c1)) gfx.FillRectangle(bsh, bounds); // Draw the overlay image if (Overlay != null) { var r = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); var s = new Rectangle(0, 0, Overlay.Width, Overlay.Height); if (OverlayAttributes == null) { gfx.DrawImage(Overlay, r, s, GraphicsUnit.Pixel); } else { gfx.DrawImage(Overlay, r, s, GraphicsUnit.Pixel, OverlayAttributes); } } // Indicator ranges foreach (var r in m_indicator_ranges) { c0 = r.Color; c1 = Gfx_.Blend(c0, Color.FromArgb(c0.A, Color.White), 0.2f); using (var bsh = new LinearGradientBrush(pt0, pt1, c0, c1)) gfx.FillRectangle(bsh, r.m_rect); } // Thumb { var r = MakeThumbRect(bounds); c0 = Gfx_.Blend(Color.White, Color.FromArgb(0x80, ThumbColor), 0.8f); c1 = ThumbColor; using (var bsh = new LinearGradientBrush(pt0, pt1, c0, c1)) gfx.FillRectangle(bsh, r); if (r.Width > 2) { using (var pen = new Pen(ThumbColor)) { gfx.DrawLine(pen, r.Left + 1, r.Top, r.Right - 1, r.Top); gfx.DrawLine(pen, r.Left + 1, r.Bottom, r.Right - 1, r.Bottom); } } } // Borders gfx.DrawRectangleRounded(SystemPens.ControlDarkDark, bounds, m_corner_radius); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Find the bounding area of the control var bounds = ClientRectangle; bounds.Inflate(-1, -1); if (bounds.Width <= 0 || bounds.Height <= 0) { return; } var gfx = e.Graphics; var total = ZoomedRange; gfx.SmoothingMode = SmoothingMode.AntiAlias; Color c0, c1; Point pt0 = new Point(bounds.Left, 0); Point pt1 = new Point(bounds.Right, 0); // Background c0 = Gfx_.Blend(Color.Black, TrackColor, 0.7f); c1 = TrackColor; using (var bsh = new LinearGradientBrush(pt0, pt1, c0, c1)) // This throws OutOfMemoryException if pt0 == pt1.. ffs MS.. gfx.FillRectangle(bsh, bounds); // Draw the overlay image if (Overlay != null) { var r = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); var s = new Rectangle(0, 0, Overlay.Width, Overlay.Height); if (OverlayAttributes == null) { gfx.DrawImage(Overlay, r, s, GraphicsUnit.Pixel); } else { gfx.DrawImage(Overlay, r, s, GraphicsUnit.Pixel, OverlayAttributes); } } // Draw the visible range if (bounds.Width > 2) { int sy = (int)(Math_.Frac(total.Beg, VisibleRange.Beg, total.End) * bounds.Height); int ey = (int)(Math_.Frac(total.Beg, VisibleRange.End, total.End) * bounds.Height); var r = new Rectangle(bounds.X + 1, bounds.Y + sy, bounds.Width - 2, ey - sy); using (var bsh = new SolidBrush(VisibleRangeColor)) { gfx.FillRectangle(bsh, r); } if (bounds.Width > 4) { using (var pen = new Pen(VisibleRangeBorderColor)) { gfx.DrawLine(pen, r.Left + 1, r.Top, r.Right - 1, r.Top); gfx.DrawLine(pen, r.Left + 1, r.Bottom, r.Right - 1, r.Bottom); } } } // Borders gfx.DrawRectangleRounded(SystemPens.ControlDarkDark, bounds, m_corner_radius); }