我正在尝试计算将从 DataGridView 打印的总页数。一旦总列长度大于总打印区域,将打印新页面。对于每个新页面,它将始终打印第 0 列,以便需要添加列宽才能获得正确的计算。
这是我迄今为止所拥有的,似乎总是缺少页码
//dgv = the DataGridView
//RectangleF printable_area = MarginBounds
float total_width = 0;
//grab the width of each column
for (int i = 0; i < dgv.ColumnCount; i++)
{
total_width += dgv.Columns[i].HeaderCell.Size.Width;
}
//divide the total width by the printable area's width
int pages = (int)Math.Ceiling(total_width / (printable_area.Size.Width));
//add to the total width the size of column 0 * the number of pages
total_width += dgv.Rows[0].Cells[0].Size.Width * pages;
//return the total number of pages that will be printed
return (int)Math.Ceiling(total_width / (printable_area.Size.Width));