如何跳转到下一个页面中的PrintDocument? [英] How to jump to the next page in a PrintDocument?

查看:249
本文介绍了如何跳转到下一个页面中的PrintDocument?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有打印要多少条形码的应用程序,但是,如果条形码的量小于的PrintDocument 它不会跳转到下一个页面。

I have an application that prints how many bar codes you want, but if the amount of bar codes is bigger than the size of the PrintDocument it doesn't jump to the next page.

我想想知道我怎么可以添加更多的页面或在的的PrintDocument

I'd like to know how can I add more pages or write in the next page of a PrintDocument.

我使用的是打印预览,显示该Windows窗体的PrintDocument。

I'm using a PrintPreview to display the PrintDocument in this Windows Form.

推荐答案

如果你联播的OnPrintPage事件中,你可以告诉的PrintDocument如果需要对PrintPageEventArguments添加另一页。

If you hookup the OnPrintPage event you can tell the PrintDocument if it needs to add another page on the 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;
}

这篇关于如何跳转到下一个页面中的PrintDocument?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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