我有一个应用程序可以打印您想要的条形码数量,但是如果条形码数量大于PrintDocument的大小,它不会跳到下一页。

我想知道如何添加更多页面或在PrintDocument的下一页中写。

我正在使用PrintPreview在此Windows窗体中显示PrintDocument。

最佳答案

如果连接OnPrintPage事件,则可以告诉PrintDocument是否需要在PrintPageEventArguments上添加另一个页面。

IEnumerator items;

public void StartPrint()
{
   PrintDocument pd = new PrintDocument();
   pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
   items = GetEnumerator();
   if (items.MoveNext())
   {
       pd.Print();
   }
}

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
    const int neededHeight = 200;
    int line =0;
    // this will be called multiple times, so keep track where you are...
    // do your drawings, calculating how much space you have left on one page
    bool more = true;
    do
    {
        // draw your bars for item, handle multilple columns if needed
        var item = items.Current;
        line++;
        // in the ev.MarginBouds the width and height of this page is available
        // you use that to see if a next row will fit
        if ((line * neededHeight) < ev.MarginBounds.Height )
        {
            break;
        }
        more = items.MoveNext();
    } while (more);
    // stop if there are no more items in your Iterator
    ev.HasMorePages = more;
}

关于c# - 如何跳到PrintDocument的下一页?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18814493/

10-10 00:58