使用printDocument打印怎么实现有页码范围的打印,也就是只想打印其中几页的内容,如2-5页的内容
不是全部打印
代码如下:
private void btnPrint_Click(object sender, System.EventArgs e)
{
printDialog1.AllowSomePages =true;
if (printDialog1.ShowDialog() == DialogResult.OK){
printDocument1.PrinterSettings = printDialog1.PrinterSettings ;
printDocument1.Print();} }
急急急!!!!

解决方案 »

  1.   

    你说的是printDialog吗
    不好使呀
      

  2.   

    俺使用的是PDF档,代码是这样写的,不知是不是你想要的东西?string Fname="c:\\" + Session.SessionID.ToString() + ".pdf";

    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
    CrDiskFileDestinationOptions.DiskFileName=Fname;

    ExportOptions CrExportOptions = myReportDoc.ExportOptions;
    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile ;
    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
    myReportDoc.Export();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.WriteFile(Fname);
    Response.Flush();
    Response.Close();
    System.IO.File.Delete(Fname);
      

  3.   

    不是的
    我想用printDocument和printDialog控制打印的页码范围
    不知道怎么实现
      

  4.   

    sorry 记错了,
    this.printDialog1.ShowDialog();
    不就显示出来了吗?
      

  5.   

    是printDialog1.AllowSomePages =true;
    不是选择区域打印
      

  6.   

    查了下MSDN,我觉得大致的步骤是这样子的:
    1.设置PrintSettings中的MinimumPage(可选择的最小页)、MaximumPage属性,将PrintSettings关联到PrintDialog;
    2.设置PrintDialog的AllowSomePages、AllowSelection属性为True,显示PrintDialg让用户设定;
    3.在PrintDocument的OnPrintPage事件处理程序中,根据PrintSettings的PrintRange、FromPage、ToPage属性来确定需要打印的页即可。希望我的研究对您有用,祝你工作愉快。
      

  7.   

    printDialog1.AllowSelection=true;
    this.printDialog1.AllowSomePages=true;
      

  8.   

    printDialog1.AllowSomePages =true;是否启用页码范围选择按钮
      

  9.   

    上面的又错了,是这个
    printDialog1.AllowSelection=true;
    是否启用页码范围选择按钮
      

  10.   

    OnPrintPage中的代码具体怎么写呢
    感谢大家的帮助
      

  11.   

    我只是给出思路,具体的用法和实现过程还是需要自己去研究的,
    建议:
    1。查看MSDN中的那几个类;
    2。买本合适的书看看。
      

  12.   

    http://study.okshare.net/it/IT09/Article_13148.html参考一下
      

  13.   

    void PrintPageEvent(object sender, PrintPageEventArgs ev)
        {
          string line = null;
          float linesPerPage = ev.MarginBounds.Height / theFont.GetHeight(ev.Graphics);
          bool isSomePages = ev.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages;
          if (isSomePages)
          {
            while (currPage < ev.PageSettings.PrinterSettings.FromPage)
            {
              for (int count = 0; count < linesPerPage; count++)
              {
                line = srToPrint.ReadLine();
                if (line == null) break;
              }
              if (line == null) return;
              currPage++;
            }
            if (currPage > ev.PageSettings.PrinterSettings.ToPage) return;
          }
          for (int count = 0; count < linesPerPage; count++)
          {
            line = srToPrint.ReadLine();
            if (line == null) break;
            ev.Graphics.DrawString(line, theFont, Brushes.Black, ev.MarginBounds.Left,
              ev.MarginBounds.Top + (count * theFont.GetHeight(ev.Graphics)), new StringFormat());
          }
          currPage++;
          if (isSomePages && currPage > ev.PageSettings.PrinterSettings.ToPage) return;
          if (line != null) ev.HasMorePages = true;
        }