大家好,我有一个应用程序可以为员工的每日时间记录创建报告。问题是打印预览对话框中的所有页面都被打印中可用的每个页面覆盖。我怎么可能解决这种问题?第 1 页的内容适用于第 1 页,第 2 页仅适用于第 2 页,反之亦然。这是我的打印代码:
private void simpleButtonOk_Click(object sender, EventArgs e)
{
try
{
countPage = 0;
CoolPrintPreviewDialog printPreview = new CoolPrintPreviewDialog();
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
printPreview.Document = doc;
Form p = (Form)printPreview;
p.WindowState = FormWindowState.Maximized;
p.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
try
{
for (int i = 1; i <= countEmployee; i++)
{
Font fontName = new Font("Calibri", 12, FontStyle.Bold);
Font fontPosition = new Font("Calibri", 12, FontStyle.Regular);
Brush colorBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString(empName, fontName, colorBrush, new Point(80, 120));
e.Graphics.DrawString(empPosition, fontPosition, colorBrush, new Point(80, 140));
e.Graphics.DrawString(empId, fontPosition, colorBrush, new Point(680, 120));
DataManipulation.PrintSelectEmployeeByMonth(i, e, comboBoxMonth, comboBoxYear, comboBoxDayFrom, comboBoxDayTo);
countPage++;
MessageBox.Show(countPage.ToString());
}
if (countPage <= countEmployee)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}