【问题标题】:How to jump to the next page in a PrintDocument?如何跳转到 PrintDocument 的下一页?
【发布时间】:2013-09-19 19:18:42
【问题描述】:

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

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

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

【问题讨论】:

标签: c# winforms printdocument


【解决方案1】:

如果您连接 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 2020-08-23
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多