Exemple #1
0
        public void AddCellText(string text, Font printFont = null)
        {
            DPrintItemText item = new DPrintItemText();

            item.Text      = text;
            item.PrintFont = printFont;

            _Cells.Add(item);
        }
Exemple #2
0
        public void AddItemText(string text, Font printFont = null, DPrintAlignment alignment = DPrintAlignment.None)
        {
            DPrintItemText item = new DPrintItemText();

            item.Text      = text;
            item.PrintFont = printFont;
            item.Alignment = alignment;

            _Items.Add(item);
        }
Exemple #3
0
        public void AddCellText(string text, Font printFont = null)
        {
            DPrintItemText item = new DPrintItemText();

            item.Text      = text;
            item.PrintFont = printFont;

            DPrintItemTableCell cell = new DPrintItemTableCell();

            cell.Item = item;
            _Cells.Add(cell);
        }
Exemple #4
0
        /// <summary>
        /// Принтиране на елемент
        /// </summary>
        private float PrintItem(PrintPageEventArgs e, float startY, float startX, float endX
                                , DPrintItem item, Font parentFont = null, DPrintAlignment alignment = DPrintAlignment.None)
        {
            Type itemType = item.GetType();

            // Текст
            if (itemType == typeof(DPrintItemText))
            {
                DPrintItemText itemText = (DPrintItemText)item;
                if (itemText.PrintFont == null)
                {
                    itemText.PrintFont = parentFont;
                }
                if (itemText.Alignment == DPrintAlignment.None)
                {
                    itemText.Alignment = alignment;
                }
                return(PrintItemText(e, startY, startX, endX, itemText));
            }
            // Таблица
            else if (itemType == typeof(DPrintItemTable))
            {
                return(PrintItemTable(e, startY, startX, endX, (DPrintItemTable)item));
            }
            // Празно място
            else if (itemType == typeof(DPrintItemBlank))
            {
                return(PrintItemBlank(e, startY, startX, endX, (DPrintItemBlank)item));
            }
            // от средата на стр.
            else if (itemType == typeof(DPrintFromMiddlePage))
            {
                return(pDocument.DefaultPageSettings.PaperSize.Height / 2);
            }
            // DataTable
            else if (itemType == typeof(DPrintItemDataRow))
            {
                return(PrintItemDataRow(e, startY, startX, endX, (DPrintItemDataRow)item));
            }
            else
            {
                return(startY);
            }
        }
Exemple #5
0
        /// <summary>
        /// Принтир ред от DataTable
        /// </summary>
        private float PrintItemDataRow(PrintPageEventArgs e, float startY, float startX, float endX, DPrintItemDataRow item)
        {
            // Margins
            float startTableY = startY + item.Margins.Top;
            float startTableX = startX + item.Margins.Left;
            float endTableX   = endX - item.Margins.Right;
            // край на таблицата по Y
            float endY = startTableY;

            PointF[] cols = item.DTable.GetColumns(startTableX, endTableX);

            for (int colIndex = 0; colIndex < cols.Length; colIndex++)
            {
                // Позиция на колоната
                PointF col = cols[colIndex];
                // Принтира елемента
                if (colIndex < item.Cells.Count)
                {
                    DPrintItem      cell            = item.Cells[colIndex];
                    DPrintAlignment columnAlignment = DPrintAlignment.None;
                    if (item.DTable.Columns.Count > colIndex)
                    {
                        DPrintItemDataColumn column = item.DTable.Columns[colIndex];
                        columnAlignment = column.Alignment;
                    }

                    if (cell.BackgroundColor.IsEmpty)
                    {
                        cell.BackgroundColor = item.BackgroundColor;
                    }
                    if (item.CountTextLine > 1)
                    {
                        Type itemType = cell.GetType();
                        // Текст
                        if (itemType == typeof(DPrintItemText))
                        {
                            DPrintItemText cellText = (DPrintItemText)cell;
                            cellText.CountTextLine = item.CountTextLine;
                        }
                    }
                    float cellY = PrintItem(e, startY, col.X, col.Y, cell
                                            , item.DTable.CellFont, columnAlignment);

                    // Максималната височина на клетката
                    if (cellY > endY)
                    {
                        endY = cellY;
                    }
                    // Слага рамка на клетката
                    if (item.CellBorder == DPrintBorderType.Solid)
                    {
                        PrintItemBorder(e.Graphics, col.X, startY, col.Y, endY);
                    }
                }
            }
            // Слага рамка на реда
            if (item.Border == DPrintBorderType.Solid)
            {
                PrintItemBorder(e.Graphics, startX, startY, endX, endY);
            }
            return(endY);
        }
Exemple #6
0
        /// <summary>
        /// Принтиране на текст
        /// </summary>
        private float PrintItemText(PrintPageEventArgs e, float startY, float startX, float endX, DPrintItemText item)
        {
            // Font на текста
            Font printFont = item.PrintFont;

            if (printFont == null)
            {
                printFont = this.Font;
            }
            // Подравняване на текста
            StringFormat sFormat = new StringFormat();

            sFormat.Alignment = CastToStringAlignment(item.Alignment);
            // Начало на текста
            float startTextX = 0;

            switch (item.Alignment)
            {
            case DPrintAlignment.Far:
                startTextX = endX;
                break;

            case DPrintAlignment.Center:
                startTextX = startX + ((endX - startX) / 2);
                break;

            case DPrintAlignment.Near:
            default:
                startTextX = startX;
                break;
            }

            int lineHeight = printFont.Height + 1;

            if (item.CountTextLine > 1)
            {
                lineHeight *= item.CountTextLine;
            }
            RectangleF textRect = new RectangleF(startX, startY, endX - startX, lineHeight);

            if (!item.BackgroundColor.IsEmpty)
            {
                SolidBrush backgroundBrush = new SolidBrush(item.BackgroundColor);
                e.Graphics.FillRectangle(backgroundBrush, textRect);
            }
            // Текста
            // e.Graphics.DrawString(item.Text, printFont, Brushes.Black, startTextX, startY, sFormat);
            e.Graphics.DrawString(item.Text, printFont, Brushes.Black, textRect, sFormat);

            return(startY + lineHeight);
        }