示例#1
0
        /// <summary>
        /// Draw Grid column headers from partition
        /// </summary>
        /// <param name="g"></param>
        /// <param name="partition">Partition to print</param>
        /// <returns></returns>
        private float DrawColumnHeaders(Graphics g, Partition partition)
        {
            PartitionBounds bounds = partition.Bounds;

            float currentY = bounds.StartY;
            float currentX = bounds.StartX;



            // Setting the LinePen that will be used to draw lines and rectangles (derived from the GridColor property of the DataGridView control)
            Pen linePen = new Pen(GridView.GridColor, 1);

            // Calculating and drawing the HeaderBounds
            RectangleF HeaderBounds = new RectangleF(currentX, currentY, bounds.Width, columnHeaderHeight);

            g.FillRectangle(
                new SolidBrush(GridView.ColumnsHeaderBackColor()),
                HeaderBounds);


            // Setting the format that will be used to print each cell of the header row
            StringFormat CellFormat = new StringFormat();

            CellFormat.Trimming    = StringTrimming.Word;
            CellFormat.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;



            // Printing each visible cell of the header row
            foreach (var column in partition.GetColumns().OrderBy(x => x.DisplayIndex))
            {
                DataGridViewHeaderCell cell = column.HeaderCell;

                CellFormat.Alignment = cell.HorizontalAlignement();


                RectangleF CellBounds = new RectangleF(currentX, currentY, columnWidths[column.Index], columnHeaderHeight);

                // Printing the cell text
                g.DrawString(column.HeaderText,
                             cell.Font(scale),
                             new SolidBrush(cell.ForeColor()),
                             CellBounds,
                             CellFormat);


                // Drawing the cell bounds
                if (GridView.RowHeadersBorderStyle != DataGridViewHeaderBorderStyle.None) // Draw the cell border only if the HeaderBorderStyle is not None
                {
                    g.DrawRectangle(linePen, currentX, currentY, columnWidths[column.Index], columnHeaderHeight);
                }


                currentX += columnWidths[column.Index];
            }

            return(currentY + columnHeaderHeight);
        }
示例#2
0
        Partition CreatePartition(
            int indexLevel, int partitionLevel, int pageNumber,
            int firstRow, int lastRow, int firstColumn, int lastColumn,
            float startx, float starty, float width, float height)
        {
            if (MustCenterPartition)
            {
                startx += (metrics.PrintAbleWidth - width) / 2.0F;
            }

            PartitionBounds bounds = new PartitionBounds()
            {
                ColSelector      = colSelector,
                RowSelector      = rowSelector,
                StartRowIndex    = firstRow,
                EndRowIndex      = lastRow,
                StartColumnIndex = firstColumn,
                EndColumnIndex   = lastColumn,
                StartX           = startx,
                StartY           = starty,
                Width            = width,
                Height           = height
            };

            if (indexLevel == 1 && TitlePrintBlock != null)
            {
                bounds.StartY += TitlePrintBlock.Rectangle.Height;
            }



            return(new Partition(
                       GridView,
                       pageNumber,
                       bounds));
        }
示例#3
0
 public Partition(DataGridView dgv, int sheetNumber, PartitionBounds bounds)
 {
     this.GridView = dgv;
     _SheetNumber  = sheetNumber;
     _Bounds       = bounds;
 }
示例#4
0
        /// <summary>
        /// Draw Grid rows from given partition
        /// </summary>
        /// <param name="g"></param>
        /// <param name="partition">Partition to print</param>
        /// <param name="currentY">Starting Y coordinate</param>
        private void DrawRows(Graphics g, Partition partition, float currentY)
        {
            PartitionBounds bounds = partition.Bounds;

            // Setting the LinePen that will be used to draw lines and rectangles
            Pen linePen = new Pen(GridView.GridColor, 1);

            // Setting the format that will be used to print each cell
            StringFormat CellFormat = new StringFormat();

            CellFormat.Trimming    = StringTrimming.Word;
            CellFormat.FormatFlags = StringFormatFlags.LineLimit;


            foreach (var row in partition.GetRows())
            {
                float rowHeight = rowsHeights[row.Index];


                // Setting the RowFore style
                SolidBrush RowForeBrush = new SolidBrush(row.ForeColor());


                // Calculating the starting x coordinate that the printing process will start from
                float currentX = bounds.StartX;



                // Calculating the entire CurrentRow bounds
                RectangleF RowBounds = new RectangleF(currentX, currentY, bounds.Width, rowHeight);

                g.FillRectangle(new SolidBrush(row.BackColor()), RowBounds);

                foreach (var column in partition.GetColumns().OrderBy(x => x.DisplayIndex))
                {
                    var cell = row.Cells[column.Index];

                    CellFormat.Alignment = cell.HorizontalAlignement();

                    RectangleF CellBounds = new RectangleF(currentX, currentY, columnWidths[column.Index], rowHeight);

                    g.FillRectangle(new SolidBrush(cell.BackColor()), CellBounds);

                    if (cell is DataGridViewImageCell)
                    {
                        Bitmap bm  = cell.Value as Bitmap;
                        PointF pos = new PointF(currentX + (columnWidths[column.Index] - bm.Width) / 2,
                                                currentY + (rowHeight - bm.Height) / 2);
                        g.DrawImage(bm, pos);
                    }
                    else
                    {
                        // Printing the cell text
                        g.DrawString(
                            cell.EditedFormattedValue.ToString(),
                            cell.Font(scale),
                            new SolidBrush(cell.ForeColor()),
                            CellBounds,
                            CellFormat);
                    }
                    // Drawing the cell bounds
                    if (GridView.CellBorderStyle != DataGridViewCellBorderStyle.None) // Draw the cell border only if the CellBorderStyle is not None
                    {
                        g.DrawRectangle(linePen, currentX, currentY, columnWidths[column.Index], rowHeight);
                    }

                    currentX += columnWidths[column.Index];
                }

                currentY += rowHeight;
            }
        }