加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何跳转到PrintDocument中的下一页?

发布时间:2020-12-15 08:43:20 所属栏目:百科 来源:网络整理
导读:我有一个应用程序可以打印您想要的条形码数量,但如果条形码的数量大于 PrintDocument的大小,则不会跳转到下一页. 我想知道如何在PrintDocument的下一页添加更多页面或写入. 我正在使用PrintPreview在此Windows窗体中显示PrintDocument. 解决方法 如果你连接O
我有一个应用程序可以打印您想要的条形码数量,但如果条形码的数量大于 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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读