C#里打印第二页功能要怎么实现,有什么可以用得上的方法吗?
就是在预览中,第一页纸放不下,想换第二张纸继续写。下面这个代码要怎么修改?privatevoidprintAllPrintDocument_PrintPage(objec...
就是在预览中,第一页纸放不下,想换第二张纸继续写。下面这个代码要怎么修改?
private void printAllPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Print a List of all current courses.
Font printFont = new Font("Arical", 10);
Font headingFont = new Font("Arical", 14, FontStyle.Bold);
float verticalPrintPositionFloat = e.MarginBounds.Top;
float horizontalPrintPositionFloat = e.MarginBounds.Left;
float lineHeightFloat = printFont.GetHeight();
//Print heading.
e.Graphics.DrawString("Current Course List As of "
+ DateTime.Now.ToShortDateString(), headingFont,
Brushes.Black, horizontalPrintPositionFloat,
verticalPrintPositionFloat);
verticalPrintPositionFloat += 2 * lineHeightFloat;
//Loop through the list to print all courses.
for (int indexInteger = 0; indexInteger < classesComboBox.Items.Count;
indexInteger++)
{
e.Graphics.DrawString(classesComboBox.Items[indexInteger].ToString(),
printFont, Brushes.Black, horizontalPrintPositionFloat,
verticalPrintPositionFloat);
verticalPrintPositionFloat += lineHeightFloat;
} 展开
private void printAllPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Print a List of all current courses.
Font printFont = new Font("Arical", 10);
Font headingFont = new Font("Arical", 14, FontStyle.Bold);
float verticalPrintPositionFloat = e.MarginBounds.Top;
float horizontalPrintPositionFloat = e.MarginBounds.Left;
float lineHeightFloat = printFont.GetHeight();
//Print heading.
e.Graphics.DrawString("Current Course List As of "
+ DateTime.Now.ToShortDateString(), headingFont,
Brushes.Black, horizontalPrintPositionFloat,
verticalPrintPositionFloat);
verticalPrintPositionFloat += 2 * lineHeightFloat;
//Loop through the list to print all courses.
for (int indexInteger = 0; indexInteger < classesComboBox.Items.Count;
indexInteger++)
{
e.Graphics.DrawString(classesComboBox.Items[indexInteger].ToString(),
printFont, Brushes.Black, horizontalPrintPositionFloat,
verticalPrintPositionFloat);
verticalPrintPositionFloat += lineHeightFloat;
} 展开
2个回答
展开全部
你可以单独复制以下代码到项目中试试,其实主要是 e.HasMorePages的运用。表示是否另开一页。
int i = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
if (i == 0)
{
i++;
e.Graphics.DrawString("asdfsdf", this.Font, new SolidBrush(Color.Red), new PointF(20f, 20f));
e.HasMorePages = true;
}
else
{
e.Graphics.DrawString("ac", this.Font, new SolidBrush(Color.Red), new PointF(50f, 50f));
e.HasMorePages = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
printDocument1.DocumentName = "2";
if (DialogResult.OK == printDialog1.ShowDialog())
{
printDocument1.Print();
}
}
int i = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
if (i == 0)
{
i++;
e.Graphics.DrawString("asdfsdf", this.Font, new SolidBrush(Color.Red), new PointF(20f, 20f));
e.HasMorePages = true;
}
else
{
e.Graphics.DrawString("ac", this.Font, new SolidBrush(Color.Red), new PointF(50f, 50f));
e.HasMorePages = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
printDocument1.DocumentName = "2";
if (DialogResult.OK == printDialog1.ShowDialog())
{
printDocument1.Print();
}
}
追问
你这个是不是只能打印一条呢?我那个的要求是假如有100条数据,一页放不下,希望打印的时候能够换页,这要怎么实现呢?
追答
服了你 e.Graphics.DrawString("ac", this.Font, new SolidBrush(Color.Red), new PointF(50f, 50f)); 这个你多弄几条不就是了
主要是e.HasMorePages 这个来实现换页的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询