private void DrawSortLabel(Graphics g, int height, int width, Point leftTop, BrushesStorage brushes) { var centerX = leftTop.X + width - Padding - sortOrderSignWidth / 2; var centerY = leftTop.Y + height / 2; var l = sortOrderSignWidth - 4; var l2 = l * 0.5F; const float sq3 = 0.57735F; var r = sq3 * l; var h = r / 2; var points = SortOrder == FastColumnSort.Ascending ? new [] { new PointF(centerX, centerY - r), new PointF(centerX - l2, centerY + h), new PointF(centerX + l2, centerY + h), } : new [] { new PointF(centerX, centerY + r), new PointF(centerX - l2, centerY - h), new PointF(centerX + l2, centerY - h), }; var brush = brushes.GetBrush(ColorSorter); g.FillPolygon(brush, points); }
/// <summary> /// draw column's header /// </summary> public void Draw(Graphics g, Font font, int height, int width, Point leftTop, Pen penUp, Pen penDn, BrushesStorage brushes) { // choose fill brush var brush = colorFillLower == colorFillUpper ? brushes.GetBrush(colorFillUpper) : (Brush) new LinearGradientBrush(new Point(0, leftTop.Y), new Point(0, leftTop.Y + height - 1), brushes.GetBrush(colorFillUpper).Color, brushes.GetBrush(colorFillLower).Color); var rect = new Rectangle(leftTop.X, leftTop.Y, width, height); g.FillRectangle(brush, leftTop.X, leftTop.Y, width, height); // outlines g.DrawLine(penUp, leftTop.X, leftTop.Y, leftTop.X + width, leftTop.Y); g.DrawLine(penUp, leftTop.X, leftTop.Y, leftTop.X, leftTop.Y + height); g.DrawLine(penDn, leftTop.X + width, leftTop.Y, leftTop.X + width, leftTop.Y + height); g.DrawLine(penDn, leftTop.X + width, leftTop.Y + height, leftTop.X, leftTop.Y + height); // text and sorting mode label var orderSignW = SortOrder == FastColumnSort.None ? 0 : SortOrderSignWidth; var maxTextW = width - Padding * 2 - orderSignW; var textCenterX = maxTextW / 2 + Padding; var columnText = !string.IsNullOrEmpty(Title) ? Title : !string.IsNullOrEmpty(PropertyDisplayName) ? PropertyDisplayName : PropertyName; var brushText = brushes.GetBrush(ColorText); g.SetClip(rect); g.DrawString(columnText, font, brushText, leftTop.X + textCenterX, leftTop.Y + height / 2, headerTextFormat); g.ResetClip(); // sorting label if (SortOrder != FastColumnSort.None) { DrawSortLabel(g, height, width, leftTop, brushes); } }
private void DrawSortLabel(Graphics g, int height, int width, Point leftTop, BrushesStorage brushes) { var centerX = leftTop.X + width - Padding - sortOrderSignWidth/2; var centerY = leftTop.Y + height/2; var l = sortOrderSignWidth - 4; var l2 = l*0.5F; const float sq3 = 0.57735F; var r = sq3*l; var h = r / 2; var points = SortOrder == FastColumnSort.Ascending ? new [] { new PointF(centerX, centerY - r), new PointF(centerX - l2, centerY + h), new PointF(centerX + l2, centerY + h), } : new [] { new PointF(centerX, centerY + r), new PointF(centerX - l2, centerY - h), new PointF(centerX + l2, centerY - h), }; var brush = brushes.GetBrush(ColorSorter); g.FillPolygon(brush, points); }
/// <summary> /// draw column's header /// </summary> public void Draw(Graphics g, Font font, int height, int width, Point leftTop, Pen penUp, Pen penDn, BrushesStorage brushes) { // choose fill brush var brush = colorFillLower == colorFillUpper ? brushes.GetBrush(colorFillUpper) : (Brush)new LinearGradientBrush(new Point(0, leftTop.Y), new Point(0, leftTop.Y + height - 1), brushes.GetBrush(colorFillUpper).Color, brushes.GetBrush(colorFillLower).Color); var rect = new Rectangle(leftTop.X, leftTop.Y, width, height); g.FillRectangle(brush, leftTop.X, leftTop.Y, width, height); // outlines g.DrawLine(penUp, leftTop.X, leftTop.Y, leftTop.X + width, leftTop.Y); g.DrawLine(penUp, leftTop.X, leftTop.Y, leftTop.X, leftTop.Y + height); g.DrawLine(penDn, leftTop.X + width, leftTop.Y, leftTop.X + width, leftTop.Y + height); g.DrawLine(penDn, leftTop.X + width, leftTop.Y + height, leftTop.X, leftTop.Y + height); // text and sorting mode label var orderSignW = SortOrder == FastColumnSort.None ? 0 : SortOrderSignWidth; var maxTextW = width - Padding * 2 - orderSignW; var textCenterX = maxTextW/2 + Padding; var columnText = !string.IsNullOrEmpty(Title) ? Title : !string.IsNullOrEmpty(PropertyDisplayName) ? PropertyDisplayName : PropertyName; var brushText = brushes.GetBrush(ColorText); g.SetClip(rect); g.DrawString(columnText, font, brushText, leftTop.X + textCenterX, leftTop.Y + height / 2, headerTextFormat); g.ResetClip(); // sorting label if (SortOrder != FastColumnSort.None) DrawSortLabel(g, height, width, leftTop, brushes); }
private void DrawCellText(int columnIndex, FastColumn column, FastCell cell, BrushesStorage brushes, Graphics g, Point leftTop, int cellWidth, int cellHeight, Font font, Brush brushFont, Color?fontColor, int rowIndex, int cellPadding) { if (userDrawCellText != null) { userDrawCellText(columnIndex, column, cell, brushes, g, leftTop, cellWidth, cellHeight, font, brushFont, fontColor, rowIndex, cellPadding); return; } var cellFont = column.ColumnFont ?? font; var brush = brushFont; if (fontColor.HasValue) { brush = brushes.GetBrush(fontColor.Value); } // apply hyperlink colors? if (column.IsHyperlinkStyleColumn) { var linkColor = column.ColorHyperlinkTextInactive; if (column.HyperlinkFontInactive != null) { cellFont = column.HyperlinkFontInactive; } if (owner.LastHoveredCell.HasValue) { var hoveredCell = owner.LastHoveredCell.Value; // is there cursor above? if (columnIndex == hoveredCell.X && rowIndex == hoveredCell.Y) { linkColor = column.ColorHyperlinkTextActive; if (column.HyperlinkFontActive != null) { cellFont = column.HyperlinkFontActive; } } } if (linkColor.HasValue) { brush = brushes.GetBrush(linkColor.Value); } } var cellString = cell.CellString; // Color render if (cell.CellValue is Color) { var c = (Color)cell.CellValue; g.FillRectangle(new SolidBrush(c), leftTop.X + cellPadding, leftTop.Y + 2, 25, cellHeight - 3); cellString = string.Format("{0}; {1}; {2}", c.B, c.G, c.R); leftTop.X += 25; } if (column.CellHAlignment == StringAlignment.Center) { g.DrawString(cellString, cellFont, brush, leftTop.X + cellWidth / 2, leftTop.Y + cellHeight / 2, cellTextFormatHCenter); } if (column.CellHAlignment == StringAlignment.Near) { g.DrawString(cellString, cellFont, brush, leftTop.X + cellPadding, leftTop.Y + cellHeight / 2, cellTextFormatHNear); } if (column.CellHAlignment == StringAlignment.Far) { g.DrawString(cellString, cellFont, brush, leftTop.X + cellWidth - cellPadding, leftTop.Y + cellHeight / 2, cellTextFormatHFar); } }
public void DrawRow( Graphics g, int rowIndex, Point leftTop, int height, List <FastColumn> columns, Pen penUp, Pen penDn, Brush brushFill, Brush brushFont, Font font, int cellPadding, BrushesStorage brushes) { if (IsGroupingRow) { var width = columns.Sum(c => c.Visible ? c.ResultedWidth : 0); var rect = new Rectangle(leftTop.X + 1, leftTop.Y + 2, width - 1, height - 2); g.FillRectangle(brushes.GetBrush(Color.DarkGray), rect); g.DrawLine(penUp, leftTop.X, leftTop.Y + 1, leftTop.X, leftTop.Y + height - 1); g.DrawLine(penDn, leftTop.X + width - 1, leftTop.Y + 2, leftTop.X + width - 1, leftTop.Y + height - 1); var image = owner.ImageList.Images[Collapsed ? "expand" : "collapse"]; if (image != null) { g.DrawImage(image, new Rectangle(new Point(), image.Size).MoveCenter( new Rectangle(leftTop.X, leftTop.Y + 1, height, height).GetCenter())); } var label = cells.Count != 0 ? cells[0].CellString : ""; rect.X += height; g.DrawString(label, new Font(font, FontStyle.Bold), brushFont, rect, new StringFormat { LineAlignment = StringAlignment.Center }); return; } var lastHoveredCell = owner.LastHoveredCell; for (var i = 0; i < columns.Count; i++) { var column = columns[i]; if (!column.Visible) { continue; } if (i >= cells.Count) { continue; } var cell = cells[i]; var width = column.ResultedWidth; // если ячейку надо показывать во всю ширину if (column.ShowClippedContent && lastHoveredCell.HasValue && lastHoveredCell.Value.X == i && lastHoveredCell.Value.Y == rowIndex && column.ImageList == null) { var textSz = g.MeasureString(cell.CellString, font); var resWd = column.Padding * 2 + (int)Math.Round(textSz.Width); if (resWd > width) { width = resWd; } } var backColor = BackgroundColor; var fontColor = FontColor; if (column.colorColumnFormatter != null) { Color?clBack, clFont; column.colorColumnFormatter(cell.CellValue, out clBack, out clFont); if (clBack.HasValue) { backColor = clBack; } if (clFont.HasValue) { fontColor = clFont; } } // fill brush var brush = brushFill; if (backColor.HasValue && !Selected) { brush = brushes.GetBrush(backColor.Value); } g.FillRectangle(brush, leftTop.X + 1, leftTop.Y + 2, width - 2, height - 2); // outline (right - left bounds) g.DrawLine(penUp, leftTop.X, leftTop.Y + 1, leftTop.X, leftTop.Y + height - 1); g.DrawLine(penDn, leftTop.X + width - 1, leftTop.Y + 2, leftTop.X + width - 1, leftTop.Y + height - 1); // text var oldBounds = g.ClipBounds; var clipBounds = new RectangleF(leftTop.X, leftTop.Y, width, height); g.SetClip(clipBounds); // draw picture? if (column.ImageList != null) { if (cell.CellValue != null) { Image img = null; if (cell.CellValue is int) { var indexImg = (int)cell.CellValue; if (indexImg >= 0 && indexImg < column.ImageList.Images.Count) { img = column.ImageList.Images[indexImg]; } } else { var keyImg = cell.CellValue is string ?(string)cell.CellValue : cell.CellValue.ToString(); img = column.ImageList.Images[keyImg]; } if (img != null) { // do draw var left = column.CellHAlignment == StringAlignment.Near ? column.Padding : column.CellHAlignment == StringAlignment.Center ? column.ResultedWidth / 2 - img.Width / 2 : column.ResultedWidth - column.Padding - img.Width; var top = height / 2 - img.Height / 2; g.DrawImage(img, leftTop.X + left, leftTop.Y + top); } } } else { // just draw text DrawCellText(i, column, cell, brushes, g, leftTop, width, height, font, brushFont, fontColor, rowIndex, cellPadding); } leftTop = new Point(leftTop.X + width, leftTop.Y); g.SetClip(oldBounds); } }
protected override void OnPaint(PaintEventArgs e) { // horz scrolling var shiftX = scrollBarH.Value; // painting using (var brushColl = new BrushesStorage()) using (var penUp = new Pen(colorCellOutlineUpper)) using (var penDn = new Pen(colorCellOutlineLower)) { var brushFillUnSel = brushColl.GetBrush(ColorCellBackground); var brushFillAlt = brushColl.GetBrush(ColorAltCellBackground); var brushFillSel = brushColl.GetBrush(ColorSelectedCellBackground); var brushFillAnchor = brushColl.GetBrush(ColorAnchorCellBackground); var brushFont = brushColl.GetBrush(ColorCellFont); var brushFontSel = brushColl.GetBrush(ColorSelectedCellFont); // draw column title var pointLeft = new Point(-shiftX, 0); var totalWidth = 0; foreach (var column in columns) { if (!column.Visible) continue; // draw the cell column.Draw(e.Graphics, FontHeader ?? Font, CaptionHeight, column.ResultedWidth, pointLeft, penUp, penDn, brushColl); pointLeft = new Point(pointLeft.X + column.ResultedWidth, pointLeft.Y); totalWidth += column.ResultedWidth; } // draw strings var fontCell = FontCell ?? Font; var leftTop = new Point(-shiftX, CaptionHeight + 1); // first displayed row index var startIndex = scrollBarV.Value >= rows.Count ? 0 : scrollBarV.Value; for (var i = startIndex; i < rows.Count; i++) { var row = rows[i]; var isAlt = (i & 1) != 0; var brushBack = row.Selected ? brushFillSel : row.anchor != FastRow.AnchorPosition.NoAnchor ? brushFillAnchor : isAlt ? brushFillAlt : brushFillUnSel; var brFont = row.Selected ? brushFontSel : brushFont; var font = (row.Selected && FontSelectedCell != null) ? FontSelectedCell : (row.anchor != FastRow.AnchorPosition.NoAnchor && FontAnchoredRow != null) ? FontAnchoredRow : fontCell; // draw horz cells margins e.Graphics.DrawLine(penUp, leftTop.X, leftTop.Y, leftTop.X + totalWidth, leftTop.Y); e.Graphics.DrawLine(penDn, leftTop.X, leftTop.Y + 1, leftTop.X + totalWidth, leftTop.Y + 1); row.DrawRow(e.Graphics, i, leftTop, CellHeight, columns, penUp, penDn, brushBack, brFont, font, CellPadding, brushColl); leftTop = new Point(leftTop.X, leftTop.Y + CellHeight); if (leftTop.Y >= Height) break; } // draw dragging if (dragCoords.HasValue) { // dragging column bool inHeader; var draggingColumnPos = GetCellUnderCursor(startDragCoords.Value.X, startDragCoords.Value.Y, out inHeader); if (draggingColumnPos.HasValue && inHeader) { // drop position var columnUnderCursorPos = GetCellUnderCursor(dragCoords.Value.X, dragCoords.Value.Y, out inHeader); var draggingColumn = columns[draggingColumnPos.Value.X]; int? columnPosition = null; if (columnUnderCursorPos.HasValue) // drag to another column { var columnUnderCursor = columns[columnUnderCursorPos.Value.X]; if(columnUnderCursor != draggingColumn) columnPosition = GetColumnPosition(columnUnderCursorPos.Value.X); // block dragging to itself if (columnPosition.HasValue && dragCoords.Value.X - columnPosition.Value > columnUnderCursor.ResultedWidth / 2) // right part of header { columnPosition = columnPosition.Value + columnUnderCursor.ResultedWidth; // block dragging var nextColumn = columns.Find(c => c.Visible && columns.IndexOf(c) > columnUnderCursorPos.Value.X); if (nextColumn == draggingColumn) columnPosition = null; } else // left part of header { // block dragging var prevColumn = columns.FindLast(c => c.Visible && columns.IndexOf(c) < columnUnderCursorPos.Value.X); if (prevColumn == draggingColumn) columnPosition = null; } } else { var firstColumnPosition = GetColumnPosition(0); if (firstColumnPosition.HasValue && dragCoords.Value.X < firstColumnPosition.Value) // drag to the left from the first column { var firstColumn = columns.FirstOrDefault(c => c.Visible); if (firstColumn != draggingColumn) columnPosition = firstColumnPosition.Value; } else // drag to the right from the last column { var lastColumnPosition = GetColumnPosition(columns.Count - 1); if (lastColumnPosition.HasValue && dragCoords.Value.X > lastColumnPosition.Value) { var lastColumn = columns.LastOrDefault(c => c.Visible); if (lastColumn != draggingColumn) columnPosition = lastColumnPosition.Value + lastColumn.ResultedWidth; } } } if (columnPosition.HasValue) e.Graphics.FillRectangle(new SolidBrush(Color.Black), columnPosition.Value - 1, 0, 3, Height); columnPosition = GetColumnPosition(draggingColumnPos.Value.X); if (columnPosition.HasValue) { brushColl.GetBrush(draggingColumn.ColorFillUpper); brushColl.GetBrush(draggingColumn.ColorFillLower); brushColl.SetAlpha(192); e.Graphics.CompositingMode = CompositingMode.SourceOver; draggingColumn.Draw(e.Graphics, FontHeader ?? Font, CaptionHeight, draggingColumn.ResultedWidth, new Point( columnPosition.Value + dragCoords.Value.X - startDragCoords.Value.X, 0), penUp, penDn, brushColl); e.Graphics.CompositingMode = CompositingMode.SourceCopy; brushColl.SetAlpha(0); } } } } if (scrollBarV.Visible) { var totalHeight = CellHeight * rows.Count + CaptionHeight + 1; var itemsLeft = (int)Math.Ceiling((totalHeight - Height) / (double)CellHeight); RecalcScrollBounds(itemsLeft); } }
protected override void OnPaint(PaintEventArgs e) { // horz scrolling var shiftX = scrollBarH.Value; // painting using (var brushColl = new BrushesStorage()) using (var penUp = new Pen(colorCellOutlineUpper)) using (var penDn = new Pen(colorCellOutlineLower)) { var brushFillUnSel = brushColl.GetBrush(ColorCellBackground); var brushFillAlt = brushColl.GetBrush(ColorAltCellBackground); var brushFillSel = brushColl.GetBrush(ColorSelectedCellBackground); var brushFillAnchor = brushColl.GetBrush(ColorAnchorCellBackground); var brushFont = brushColl.GetBrush(ColorCellFont); var brushFontSel = brushColl.GetBrush(ColorSelectedCellFont); // draw column title var pointLeft = new Point(-shiftX, 0); var totalWidth = 0; foreach (var column in columns) { if (!column.Visible) { continue; } // draw the cell column.Draw(e.Graphics, FontHeader ?? Font, CaptionHeight, column.ResultedWidth, pointLeft, penUp, penDn, brushColl); pointLeft = new Point(pointLeft.X + column.ResultedWidth, pointLeft.Y); totalWidth += column.ResultedWidth; } // draw strings var fontCell = FontCell ?? Font; var leftTop = new Point(-shiftX, CaptionHeight + 1); // first displayed row index var startIndex = scrollBarV.Value >= rows.Count ? 0 : scrollBarV.Value; for (var i = startIndex; i < rows.Count; i++) { var row = rows[i]; var isAlt = (i & 1) != 0; var brushBack = row.Selected ? brushFillSel : row.anchor != FastRow.AnchorPosition.NoAnchor ? brushFillAnchor : isAlt ? brushFillAlt : brushFillUnSel; var brFont = row.Selected ? brushFontSel : brushFont; var font = (row.Selected && FontSelectedCell != null) ? FontSelectedCell : (row.anchor != FastRow.AnchorPosition.NoAnchor && FontAnchoredRow != null) ? FontAnchoredRow : fontCell; // draw horz cells margins e.Graphics.DrawLine(penUp, leftTop.X, leftTop.Y, leftTop.X + totalWidth, leftTop.Y); e.Graphics.DrawLine(penDn, leftTop.X, leftTop.Y + 1, leftTop.X + totalWidth, leftTop.Y + 1); row.DrawRow(e.Graphics, i, leftTop, CellHeight, columns, penUp, penDn, brushBack, brFont, font, CellPadding, brushColl); leftTop = new Point(leftTop.X, leftTop.Y + CellHeight); if (leftTop.Y >= Height) { break; } } // draw dragging if (dragCoords.HasValue) { // dragging column bool inHeader; var draggingColumnPos = GetCellUnderCursor(startDragCoords.Value.X, startDragCoords.Value.Y, out inHeader); if (draggingColumnPos.HasValue && inHeader) { // drop position var columnUnderCursorPos = GetCellUnderCursor(dragCoords.Value.X, dragCoords.Value.Y, out inHeader); var draggingColumn = columns[draggingColumnPos.Value.X]; int?columnPosition = null; if (columnUnderCursorPos.HasValue) // drag to another column { var columnUnderCursor = columns[columnUnderCursorPos.Value.X]; if (columnUnderCursor != draggingColumn) { columnPosition = GetColumnPosition(columnUnderCursorPos.Value.X); // block dragging to itself } if (columnPosition.HasValue && dragCoords.Value.X - columnPosition.Value > columnUnderCursor.ResultedWidth / 2) // right part of header { columnPosition = columnPosition.Value + columnUnderCursor.ResultedWidth; // block dragging var nextColumn = columns.Find(c => c.Visible && columns.IndexOf(c) > columnUnderCursorPos.Value.X); if (nextColumn == draggingColumn) { columnPosition = null; } } else // left part of header { // block dragging var prevColumn = columns.FindLast(c => c.Visible && columns.IndexOf(c) < columnUnderCursorPos.Value.X); if (prevColumn == draggingColumn) { columnPosition = null; } } } else { var firstColumnPosition = GetColumnPosition(0); if (firstColumnPosition.HasValue && dragCoords.Value.X < firstColumnPosition.Value) // drag to the left from the first column { var firstColumn = columns.FirstOrDefault(c => c.Visible); if (firstColumn != draggingColumn) { columnPosition = firstColumnPosition.Value; } } else // drag to the right from the last column { var lastColumnPosition = GetColumnPosition(columns.Count - 1); if (lastColumnPosition.HasValue && dragCoords.Value.X > lastColumnPosition.Value) { var lastColumn = columns.LastOrDefault(c => c.Visible); if (lastColumn != draggingColumn) { columnPosition = lastColumnPosition.Value + lastColumn.ResultedWidth; } } } } if (columnPosition.HasValue) { e.Graphics.FillRectangle(new SolidBrush(Color.Black), columnPosition.Value - 1, 0, 3, Height); } columnPosition = GetColumnPosition(draggingColumnPos.Value.X); if (columnPosition.HasValue) { brushColl.GetBrush(draggingColumn.ColorFillUpper); brushColl.GetBrush(draggingColumn.ColorFillLower); brushColl.SetAlpha(192); e.Graphics.CompositingMode = CompositingMode.SourceOver; draggingColumn.Draw(e.Graphics, FontHeader ?? Font, CaptionHeight, draggingColumn.ResultedWidth, new Point( columnPosition.Value + dragCoords.Value.X - startDragCoords.Value.X, 0), penUp, penDn, brushColl); e.Graphics.CompositingMode = CompositingMode.SourceCopy; brushColl.SetAlpha(0); } } } } if (scrollBarV.Visible) { var totalHeight = CellHeight * rows.Count + CaptionHeight + 1; var itemsLeft = (int)Math.Ceiling((totalHeight - Height) / (double)CellHeight); RecalcScrollBounds(itemsLeft); } }
private void OnUserDrawCellText(int columnIndex, FastColumn column, FastCell cell, BrushesStorage brushes, Graphics g, Point leftTop, int cellWidth, int cellHeightI, Font font, Brush brushFont, Color? fontColor, int rowIndex, int cellPaddingI) { if (userDrawCellText != null) userDrawCellText(columnIndex, column, cell, brushes, g, leftTop, cellWidth, cellHeightI, font, brushFont, fontColor, rowIndex, cellPaddingI); }
private void DrawCellText(int columnIndex, FastColumn column, FastCell cell, BrushesStorage brushes, Graphics g, Point leftTop, int cellWidth, int cellHeight, Font font, Brush brushFont, Color? fontColor, int rowIndex, int cellPadding) { if (userDrawCellText != null) { userDrawCellText(columnIndex, column, cell, brushes, g, leftTop, cellWidth, cellHeight, font, brushFont, fontColor, rowIndex, cellPadding); return; } var cellFont = column.ColumnFont ?? font; var brush = brushFont; if (fontColor.HasValue) brush = brushes.GetBrush(fontColor.Value); // apply hyperlink colors? if (column.IsHyperlinkStyleColumn) { var linkColor = column.ColorHyperlinkTextInactive; if (column.HyperlinkFontInactive != null) cellFont = column.HyperlinkFontInactive; if (owner.LastHoveredCell.HasValue) { var hoveredCell = owner.LastHoveredCell.Value; // is there cursor above? if (columnIndex == hoveredCell.X && rowIndex == hoveredCell.Y) { linkColor = column.ColorHyperlinkTextActive; if (column.HyperlinkFontActive != null) cellFont = column.HyperlinkFontActive; } } if (linkColor.HasValue) brush = brushes.GetBrush(linkColor.Value); } var cellString = cell.CellString; // Color render if (cell.CellValue is Color) { var c = (Color) cell.CellValue; g.FillRectangle(new SolidBrush(c), leftTop.X + cellPadding, leftTop.Y + 2, 25, cellHeight - 3); cellString = string.Format("{0}; {1}; {2}", c.B, c.G, c.R); leftTop.X += 25; } if (column.CellHAlignment == StringAlignment.Center) g.DrawString(cellString, cellFont, brush, leftTop.X + cellWidth / 2, leftTop.Y + cellHeight / 2, cellTextFormatHCenter); if (column.CellHAlignment == StringAlignment.Near) g.DrawString(cellString, cellFont, brush, leftTop.X + cellPadding, leftTop.Y + cellHeight / 2, cellTextFormatHNear); if (column.CellHAlignment == StringAlignment.Far) g.DrawString(cellString, cellFont, brush, leftTop.X + cellWidth - cellPadding, leftTop.Y + cellHeight / 2, cellTextFormatHFar); }
public void DrawRow( Graphics g, int rowIndex, Point leftTop, int height, List<FastColumn> columns, Pen penUp, Pen penDn, Brush brushFill, Brush brushFont, Font font, int cellPadding, BrushesStorage brushes) { if (IsGroupingRow) { var width = columns.Sum(c => c.Visible ? c.ResultedWidth : 0); var rect = new Rectangle(leftTop.X + 1, leftTop.Y + 2, width - 1, height - 2); g.FillRectangle(brushes.GetBrush(Color.DarkGray), rect); g.DrawLine(penUp, leftTop.X, leftTop.Y + 1, leftTop.X, leftTop.Y + height - 1); g.DrawLine(penDn, leftTop.X + width - 1, leftTop.Y + 2, leftTop.X + width - 1, leftTop.Y + height - 1); var image = owner.ImageList.Images[Collapsed ? "expand" : "collapse"]; if (image != null) { g.DrawImage(image, new Rectangle(new Point(), image.Size).MoveCenter( new Rectangle(leftTop.X, leftTop.Y + 1, height, height).GetCenter())); } var label = cells.Count != 0 ? cells[0].CellString : ""; rect.X += height; g.DrawString(label, new Font(font, FontStyle.Bold), brushFont, rect, new StringFormat {LineAlignment = StringAlignment.Center}); return; } var lastHoveredCell = owner.LastHoveredCell; for (var i = 0; i < columns.Count; i++) { var column = columns[i]; if (!column.Visible) continue; if (i >= cells.Count) continue; var cell = cells[i]; var width = column.ResultedWidth; // если ячейку надо показывать во всю ширину if (column.ShowClippedContent && lastHoveredCell.HasValue && lastHoveredCell.Value.X == i && lastHoveredCell.Value.Y == rowIndex && column.ImageList == null) { var textSz = g.MeasureString(cell.CellString, font); var resWd = column.Padding * 2 + (int) Math.Round(textSz.Width); if (resWd > width) width = resWd; } var backColor = BackgroundColor; var fontColor = FontColor; if (column.colorColumnFormatter != null) { Color? clBack, clFont; column.colorColumnFormatter(cell.CellValue, out clBack, out clFont); if (clBack.HasValue) backColor = clBack; if (clFont.HasValue) fontColor = clFont; } // fill brush var brush = brushFill; if (backColor.HasValue && !Selected) brush = brushes.GetBrush(backColor.Value); g.FillRectangle(brush, leftTop.X + 1, leftTop.Y + 2, width - 2, height - 2); // outline (right - left bounds) g.DrawLine(penUp, leftTop.X, leftTop.Y + 1, leftTop.X, leftTop.Y + height - 1); g.DrawLine(penDn, leftTop.X + width - 1, leftTop.Y + 2, leftTop.X + width - 1, leftTop.Y + height - 1); // text var oldBounds = g.ClipBounds; var clipBounds = new RectangleF(leftTop.X, leftTop.Y, width, height); g.SetClip(clipBounds); // draw picture? if (column.ImageList != null) { if (cell.CellValue != null) { Image img = null; if (cell.CellValue is int) { var indexImg = (int) cell.CellValue; if (indexImg >= 0 && indexImg < column.ImageList.Images.Count) img = column.ImageList.Images[indexImg]; } else { var keyImg = cell.CellValue is string ? (string) cell.CellValue : cell.CellValue.ToString(); img = column.ImageList.Images[keyImg]; } if (img != null) { // do draw var left = column.CellHAlignment == StringAlignment.Near ? column.Padding : column.CellHAlignment == StringAlignment.Center ? column.ResultedWidth / 2 - img.Width / 2 : column.ResultedWidth - column.Padding - img.Width; var top = height / 2 - img.Height / 2; g.DrawImage(img, leftTop.X + left, leftTop.Y + top); } } } else { // just draw text DrawCellText(i, column, cell, brushes, g, leftTop, width, height, font, brushFont, fontColor, rowIndex, cellPadding); } leftTop = new Point(leftTop.X + width, leftTop.Y); g.SetClip(oldBounds); } }
private void OnUserDrawCellText(int columnIndex, FastColumn column, FastCell cell, BrushesStorage brushes, Graphics g, Point leftTop, int cellWidth, int cellHeightI, Font font, Brush brushFont, Color?fontColor, int rowIndex, int cellPaddingI) { if (userDrawCellText != null) { userDrawCellText(columnIndex, column, cell, brushes, g, leftTop, cellWidth, cellHeightI, font, brushFont, fontColor, rowIndex, cellPaddingI); } }