示例#1
0
 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);
     }
 }
示例#2
0
        public FastRow(FastGrid owner, object obj, Dictionary <FastColumn, PropertyInfo> columnProperty)
        {
            this.owner  = owner;
            ValueObject = obj;
            if (owner.colorFormatter != null)
            {
                Color?clBack, clFont;
                owner.colorFormatter(ValueObject, out clBack, out clFont);
                BackgroundColor = clBack;
                FontColor       = clFont;
            }

            string[] strings = null;
            if (owner.rowExtraFormatter != null)
            {
                strings = owner.rowExtraFormatter(obj, columnProperty.Select(propertyInfo => propertyInfo.Key).ToList());
            }

            var counter = 0;

            foreach (var colPair in columnProperty)
            {
                var cell = new FastCell();
                if (colPair.Value == null)
                {
                    cells.Add(cell);
                    continue;
                }
                // do format value
                var proVal = colPair.Value.GetValue(obj, null);
                cell.CellValue  = proVal;
                cell.CellString = strings == null ?
                                  (colPair.Key.formatter != null ? colPair.Key.formatter(proVal)
                    : colPair.Key.rowFormatter != null ? colPair.Key.rowFormatter(obj)
                    : proVal == null
                    ? colPair.Key.NullString
                    : ObjectToString(proVal, colPair.Key.FormatString, colPair.Key.FractionDigits)) : strings[counter++];
                if (colPair.Key.cellFormatting != null)
                {
                    var args = new CellFormattingEventArgs
                    {
                        cellValue      = cell.CellValue,
                        resultedString = cell.CellString,
                        column         = colPair.Key,
                        rowValue       = obj,
                    };
                    colPair.Key.cellFormatting(args);
                    cell.CellString = args.resultedString;
                }
                cells.Add(cell);
            }
        }
示例#3
0
        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);
            }
        }