使用的PrintDocument打印多个页面 [英] Using PrintDocument to print multiple pages

查看:2340
本文介绍了使用的PrintDocument打印多个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印发票。发票应该能够对多页打印,但是这就是问题出在哪里踢,我可以完美打印在单页上的发票,但只要发票不适合在一个页面上,将打印作业刚刚退出上第一页。



下面是我使用的代码。 artikelen'是文章(列表)名单。我看过几个类似的例子,我相当肯定我在这里失去了一些东西。



(编辑:一些unneccesary代码删除)

 公共无效PrintA4Factuur()
{$ b $ = BP新的PrintDocument();
p.PrintPage + =
新PrintPageEventHandler(的PrintPage);
printPreviewDialog.Document = P;
printPreviewDialog.ShowDialog();
}

无效的PrintPage(对象sender1,PrintPageEventArgs E1)
{
图形G = e1.Graphics;
INT yPos = 320;
浮动pageHeight = e1.MarginBounds.Height;
INT artikelPosition = 0;
,而(yPos + 100℃pageHeight
和;&安培; artikelPosition< this.artikelen.Count)
{
//使用物品的东西(在不同的矩形打印的详细信息

artikelPosition + = 1;
yPos + = 20;
}

如果(artikelPosition< this.artikelen.Count)
{
e1.HasMorePages = TRUE;
的回报;
}
,否则
{
e1.HasMorePages = FALSE;
}
}


解决方案

我发现你的代码做相反的:如果它打印多个页面,它会继续打印到无穷大。



请尝试移动索引位置变量的PrintPage 事件,因为设置回零的时候将它设置为重新开始:

  INT artikelPosition = 0; 

重置它,当你开始打印:

 公共无效PrintA4Factuur()
{
artikelPosition = 0
$ b $ = BP新的PrintDocument();
p.PrintPage + =的PrintPage;
printPreviewDialog.Document = P;
printPreviewDialog.ShowDialog();
}



然后把它注释掉在你的PrintPage常规:

 无效的PrintPage(对象sender1,PrintPageEventArgs E1)
{
图形G = e1.Graphics;
INT yPos = 320;
浮动pageHeight = e1.MarginBounds.Height;

// INT artikelPosition = 0;

//继续代码
}


I'm trying to print invoices. Invoices should be able to be printed on multiple pages, but that's where the problem kicks in. I can perfectly print an invoice on a single page, but as soon as the invoice doesn't fit on a single page, the printjob just quits on the first page.

Here's the code I'm using. 'artikelen' is a list of articles (List). I have read several similar examples, and I'm fairly sure I'm missing something here.

(Edited: some unneccesary code deleted)

public void PrintA4Factuur()
    {
        p = new PrintDocument();
        p.PrintPage +=
            new PrintPageEventHandler(printPage);
        printPreviewDialog.Document = p;
        printPreviewDialog.ShowDialog();
    }

void printPage(object sender1, PrintPageEventArgs e1)
    {
Graphics g = e1.Graphics;
int yPos = 320;
float pageHeight = e1.MarginBounds.Height;
int artikelPosition = 0;
while (yPos + 100 < pageHeight
            && artikelPosition < this.artikelen.Count)
        {
            // Do stuff with articles (printing details in different rectangles

            artikelPosition += 1;
            yPos += 20;
        }

        if (artikelPosition < this.artikelen.Count)
        {
            e1.HasMorePages = true;
            return;
        }
        else
        {
            e1.HasMorePages = false;
        }
}

解决方案

I found your code to do the opposite: if it prints more than one page, it continues to print into infinity.

Try moving your index position variable outside of the PrintPage event, because setting it back to zero just sets it to the beginning again:

int artikelPosition = 0;

Reset it when you start the printing:

public void PrintA4Factuur()
{
  artikelPosition = 0

  p = new PrintDocument();
  p.PrintPage += printPage;
  printPreviewDialog.Document = p;
  printPreviewDialog.ShowDialog();
}

Then comment it out in your PrintPage routine:

void printPage(object sender1, PrintPageEventArgs e1)
{
  Graphics g = e1.Graphics;
  int yPos = 320;
  float pageHeight = e1.MarginBounds.Height;

  // int artikelPosition = 0;

  // continue with code
}

这篇关于使用的PrintDocument打印多个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆