PrintDialog打印指定页
点击打印按钮
if (this.printDialog1.ShowDialog() == DialogResult.OK) //弹出打印机设置框
{
Pages = 0; //当前页清零
if (printDialog1.PrinterSettings.PrintRange == PrintRange.SomePages) //在此处判断,是否选择了"页"选项,还是"全部"
{
page = printDialog1.Document.PrinterSettings.FromPage; //输入的最小页
maxpage = printDialog1.Document.PrinterSettings.ToPage;
//输入的最大页
this.printDialog1.Document.Print();
}
else
{
this.printDialog1.Document.Print();
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Pages++;
e.Graphics.DrawString("记录", new Font("宋体", 9), Brushes.Black, 20, 220);
e.Graphics.DrawString("区域", new Font("宋体", 9), Brushes.Black, 90, 220);
e.Graphics.DrawString("位置", new Font("宋体", 9), Brushes.Black, 160, 220);
e.Graphics.DrawString("段号", new Font("宋体", 9), Brushes.Black, 230, 220);
e.Graphics.DrawString("品项", new Font("宋体", 9), Brushes.Black, 300, 220);
e.Graphics.DrawString("部门", new Font("宋体", 9), Brushes.Black, 370, 220);
e.Graphics.DrawString("SKU编号", new Font("宋体", 9), Brushes.Black, 440, 220);
e.Graphics.DrawString("商品名称", new Font("宋体", 9), Brushes.Black, 570, 220);
e.Graphics.DrawString("售价", new Font("宋体", 9), Brushes.Black, 690, 220);
e.Graphics.DrawString("数量", new Font("宋体", 9), Brushes.Black, 750, 220);
e.Graphics.DrawString("————————————————————————————————————————————————————————————————", new Font("宋体", 9), Brushes.Black, 10, 240);
........................
if (page != 0 && maxpage != 0)
{
if (Pages >= maxpage) //判断当前页是否大于等于最大页
{
e.HasMorePages = false;
return;
}
else
e.HasMorePages = true;
//page++;
}
}
这样只是打印效果是从第一页到输入的页数。
假设输入4 则打印是从第一页到第四页。 怎么把前面的页数不打印呢?
补充:.NET技术 , C#