internal void PaintTo(Graphics g, Rectangle rectangle, DynamicList list, DynamicListColumn column, bool isMouseEntered) { Rectangle fillRectangle = rectangle; fillRectangle.Width += 1; if (highlightBrush != null && isMouseEntered) { g.FillRectangle(highlightBrush, fillRectangle); } else { bool isActivated = list.IsActivated; Brush bgBrush = GetBrush(isActivated, backgroundBrush, backgroundBrushInactive); if (bgBrush == null) { bgBrush = GetBrush(isActivated, column.BackgroundBrush, column.BackgroundBrushInactive); if (isActivated && list.RowAtMousePosition == row && column.RowHighlightBrush != null) { bgBrush = column.RowHighlightBrush; } } g.FillRectangle(bgBrush, fillRectangle); } if (Paint != null) { Paint(this, new ItemPaintEventArgs(g, rectangle, fillRectangle, list, column, this, isMouseEntered)); } if (text.Length > 0) { g.DrawString(text, font, textBrush, rectangle, textFormat); } }
public ItemPaintEventArgs(Graphics graphics, Rectangle rectangle, Rectangle fillRectangle, DynamicList list, DynamicListColumn column, DynamicListItem item, bool isMouseEntered) : base(graphics, rectangle) { this.fillRectangle = fillRectangle; this.list = list; this.column = column; this.item = item; this.isMouseEntered = isMouseEntered; }
protected override void OnPaint(PaintEventArgs e) { //Debug.WriteLine("OnPaint"); Graphics g = e.Graphics; allowedControls.Clear(); int columnIndex = -1; foreach (DynamicListColumn col in Columns) { columnIndex += 1; if (!col.AutoSize) { continue; } int minimumWidth = DynamicListColumn.DefaultWidth; foreach (DynamicListRow row in Rows) { DynamicListItem item = row[columnIndex]; item.MeasureMinimumWidth(e.Graphics, ref minimumWidth); } col.MinimumWidth = minimumWidth; } int controlIndex = 0; int xPos; int yPos = -scrollOffset; Size clientSize = ClientSize; foreach (DynamicListRow row in Rows) { if (yPos + row.Height > 0 && yPos < clientSize.Height) { xPos = 0; for (columnIndex = 0; columnIndex < columns.Count; columnIndex++) { DynamicListColumn col = columns[columnIndex]; Rectangle rect = new Rectangle(xPos, yPos, col.Width, row.Height); if (columnIndex == columns.Count - 1) { rect.Width = clientSize.Width - 1 - rect.Left; } DynamicListItem item = row[columnIndex]; Control ctl = item.Control; if (ctl != null) { allowedControls.Add(ctl); if (rect != ctl.Bounds) { ctl.Bounds = rect; } if (!this.Controls.Contains(ctl)) { this.Controls.Add(ctl); this.Controls.SetChildIndex(ctl, controlIndex); } controlIndex += 1; } else { item.PaintTo(e.Graphics, rect, this, col, item == itemAtMousePosition); } xPos += col.Width + 1; } } yPos += row.Height + lineMarginY; } xPos = 0; Form containerForm = FindForm(); bool isFocused; if (containerForm is IActivatable) { isFocused = (containerForm as IActivatable).IsActivated; } else { isFocused = this.Focused; } for (columnIndex = 0; columnIndex < columns.Count - 1; columnIndex++) { DynamicListColumn col = columns[columnIndex]; xPos += col.Width + 1; Color separatorColor; if (isFocused) { separatorColor = col.ColumnSeperatorColor; if (separatorColor.IsEmpty) { separatorColor = col.ColumnSeperatorColorInactive; } } else { separatorColor = col.ColumnSeperatorColorInactive; if (separatorColor.IsEmpty) { separatorColor = col.ColumnSeperatorColor; } } if (separatorColor.IsEmpty) { separatorColor = BackColor; } using (Pen separatorPen = new Pen(separatorColor)) { e.Graphics.DrawLine(separatorPen, xPos - 1, 1, xPos - 1, Math.Min(clientSize.Height, yPos) - 2); } } removedControls.Clear(); foreach (Control ctl in Controls) { if (!allowedControls.Contains(ctl)) { removedControls.Add(ctl); } } foreach (Control ctl in removedControls) { Debug.WriteLine("Removing control"); Controls.Remove(ctl); Debug.WriteLine("Control removed"); } allowedControls.Clear(); removedControls.Clear(); base.OnPaint(e); }
internal void PaintTo(Graphics g, Rectangle rectangle, DynamicList list, DynamicListColumn column, bool isMouseEntered) { Rectangle fillRectangle = rectangle; fillRectangle.Width += 1; if (highlightBrush != null && isMouseEntered) { g.FillRectangle(highlightBrush, fillRectangle); } else { bool isActivated = list.IsActivated; Brush bgBrush = GetBrush(isActivated, backgroundBrush, backgroundBrushInactive); if (bgBrush == null) { bgBrush = GetBrush(isActivated, column.BackgroundBrush, column.BackgroundBrushInactive); if (isActivated && list.RowAtMousePosition == row && column.RowHighlightBrush != null) bgBrush = column.RowHighlightBrush; } g.FillRectangle(bgBrush, fillRectangle); } if (Paint != null) { Paint(this, new ItemPaintEventArgs(g, rectangle, fillRectangle, list, column, this, isMouseEntered)); } if (text.Length > 0) { g.DrawString(text, font, textBrush, rectangle, textFormat); } }