当然不行了,你的 int printingRowNumber =1;//记录正在打印的行索引
int pageNumber        =0;//需要打印的总页数
int printingPageNumber=0;//当前正在打印的页索引是局部变量,在打印的过程中如果要打印附加页那么这些局部变量重新负值,就是说打印一次附加页就是整个printDocument1_PrintPage 重新运行一边,所以你始终打印的是第一页。
你把上面那些控制数据改成全局变量就可了。

解决方案 »

  1.   

    楼上正解
    printDocument1_PrintPage是一页一页来的
    打一页,HasMorePages,再打一页
      

  2.   

    to linzsoft(邪邪)
    我把相关控制变量该为全局了,结果还是没有改变,奇怪的很,难道我的printDocument1_PrintPage事件函数中还有其他问题,好郁闷啊
      

  3.   

    如果是照上面两位的说法,我的printDocument1_PrintPage事件函数中的循环控制也有要改,我改后又试了一次,结果预览还是只有一页,怎么回事呢
      

  4.   

    //计算确定要打印的总页数
    if((gridCtrl.GetCellRect(gridCtrl.GetCell((gridCtrl.rowList.Count-1),0)).Bottom)%(e.MarginBounds.Bottom-e.MarginBounds.Top) != 0)
    {
    pageNumber +=(gridCtrl.GetCellRect(gridCtrl.GetCell((gridCtrl.rowList.Count-1),0)).Bottom)/(e.MarginBounds.Bottom-e.MarginBounds.Top)+1;
    }
    else
    {
                                        //刚好在某页最后一行打印完行数据
    pageNumber +=(gridCtrl.GetCellRect(gridCtrl.GetCell((gridCtrl.rowList.Count-1),0)).Bottom)/(e.MarginBounds.Bottom-e.MarginBounds.Top);
    }计算确定要打印的总页数 也应该在 printDocument1_PrintPage 前进行。这样吧,你按照下面的流程来做就没问题一:
    在运行 printDocument1_PrintPage 前初始化打印数据,
    1: 确认要打多少页 ,记录这个数据。
    int pageNumber
    2:初始化
    int printingRowNumber =1;
    int printingPageNumber=0;二:
    开始打印printDocument1_PrintPage
    1:根据你要打得表格进行控制流程