用的是连续纸,纸的大小是:
private PaperSize myPageSize = new PaperSize("MySheet",860,550);
模拟显示正常,但实际打印总是多打印一张同样大小的白纸。
我也在“服务器属性”里定义了名称为“MySheet”同样大小
的纸型并在打印首选项里选中。
代码如下:
public class PrtSheet : PrintDocument
{
private int TotalPages = 1;
private int CurrentPage = 0;
private Font TitleFont = null;
private Font ContentFont = null;
private float leftMargin = 0;
private float topMargin = 0;
//表头坐标
private float XtableHead = 0;
private float YtableHead = 0;
//表格宽度
private int TableWidth = 770;
private int TableEachGrid = 20;//每格纵向宽度//定义纸张大小
private PaperSize myPageSize = new PaperSize("MySheet",860,550);public PrtDeployTaskSheet():base()
{
}//重写 OnBeginPrint 以设置
protected override void OnBeginPrint(PrintEventArgs ev) 
{
base.OnBeginPrint(ev);
this.DefaultPageSettings.PaperSize = myPageSize;TitleFont = new Font("楷体_GB2312", 14);
ContentFont = new Font("宋体",10);
}
等待继续...

解决方案 »

  1.   

    继续:
    继续:
    //#000 必须先打印标题,给标题的坐标进行赋值
    private void PrintTitle(PrintPageEventArgs ev)
    {
    string sTitle = "深圳市环球股份有限公司";
    string sSubTitle = "帐单";
    string sSubHeader = "日期: "+DateTime.Now.ToShortDateString();
    string sPageShow = "第 " + (this.CurrentPage+1).ToString() + " 页";
    float xPos1 = leftMargin + 268;
    float yPos1 = topMargin + 20;
    float yPos2 = yPos1 + TitleFont.GetHeight(ev.Graphics);
    float xPos2 = xPos1 + 90;
    float xPos3 = 600;
    float yPos3 = yPos2 + TitleFont.GetHeight(ev.Graphics) + 10;
    //在这里给表头原点赋值
    this.XtableHead = leftMargin + 28;
    this.YtableHead = yPos3 + 20;
    ev.Graphics.DrawString(sTitle,Brushes.Black,xPos1,yPos1);
    ev.Graphics.DrawString(sSubTitle,TitleFont,Brushes.Black,xPos2,yPos2);
    ev.Graphics.DrawString(sHeader,ContentFont,Brushes.Black,xPos3,yPos3);
    ev.Graphics.DrawString(sPageShow,ContentFont,Brushes.Black,xPos3,yPos);
    }//重写 OnPrintPage 以为文档提供打印逻辑
    protected override void OnPrintPage(PrintPageEventArgs ev) 
    {
    base.OnPrintPage(ev) ;this.PrintTitle(ev);
    this.PrintTableHead(ev);if(this.CurrentPage<this.TotalPages)
                    ev.HasMorePages = true ;
    else
    ev.HasMorePages = false;this.CurrentPage++;
    }
    等待继续...
      

  2.   

    贴好了:
    这里是调用以上类的代码:
    private void button1_Click(object sender, System.EventArgs e)
    {
    PrtDeployTaskSheet pd = new PrtDeployTaskSheet(); 
    pd.PrinterSettings.DefaultPageSettings.PaperSize = this.myPageSize;
    try 
    {
    PrintDialog dlg = new PrintDialog() ;
    dlg.Document = pd;
    DialogResult result = dlg.ShowDialog();
    if (result == DialogResult.OK) 
    {
    pd.Print();
    }

    catch(Exception ex) 
    {
    MessageBox.Show("打印文件时发生错误 - " + ex.Message);
    }
    finally
    {
    pd.Dispose();
    }
    }
    代码贴完了,请高手作答...
      

  3.   

    看一看
    if(this.CurrentPage<this.TotalPages)
                    ev.HasMorePages = true ;这句,只有起点都是0或1时才这样
    改成
    if(this.CurrentPage<this.TotalPages-1)
                    ev.HasMorePages = true ;
    一试
      

  4.   

    谢谢长江支流,这一句是错了。
    但该句:
    if(this.CurrentPage<this.TotalPages)
                    ev.HasMorePages = true ;
    只影响总页数。
    按照你的说法修改后总页数正确,但依然会在每一页后
    打印多一张白纸。
    修改以下参数可以测试效果:
    private int TotalPages = 1;
    private int CurrentPage = 0;