如题,C#中的printpreviewdialog预览时只能显示几个工具和简单按钮,如何对这几个按钮进行修改,或加入几个自己做的新按钮,或减少,如何实现,最好有代码
小生先谢谢了

解决方案 »

  1.   

    using   System;   
      using   System.Collections.Generic;   
      using   System.Text;   
        
      using   System.Drawing;   
      using   System.Drawing.Printing;   
      using   System.Windows.Forms;   
      using   System.IO;   
        
      namespace   MyCCTV   
      {   
              sealed   class   TextFilePrinter   
              {   
                      string   fileName;   
                      Encoding   theEncode;   
                      Font   theFont;   
                      StreamReader   srToPrint;   
                      int   currPage;   
        
                      public   TextFilePrinter(string   fileName)   
                              :   this(fileName,   Encoding.GetEncoding(936),   new   Font("MS   UI   Gothic",   9))   
                      {   
                      }   
        
                      public   TextFilePrinter(string   fileName,   Encoding   theEncode,   Font   theFont)   
                      {   
                              this.fileName   =   fileName;   
                              this.theEncode   =   theEncode;   
                              this.theFont   =   theFont;   
                      }   
        
                      public   void   Print()   
                      {   
                              using   (srToPrint   =   new   StreamReader(fileName,   theEncode))   
                              {   
                                      PrintDialog   dlg   =   new   PrintDialog();   
                                      dlg.Document   =   GetPrintDocument();   
                                      dlg.AllowSomePages   =   true;   
                                      dlg.AllowPrintToFile   =   false;   
                                      if   (dlg.ShowDialog()   ==   DialogResult.OK)   dlg.Document.Print();   
                              }   
                      }   
        
                      public   void   View()   
                      {   
                              using   (srToPrint   =   new   StreamReader(fileName,   theEncode))   
                              {   
                                      PrintPreviewDialog   dlg   =   new   PrintPreviewDialog();   
                                      dlg.Document   =   GetPrintDocument();   
                                      dlg.ShowDialog();   
                              }   
                      }   
        
                      PrintDocument   GetPrintDocument()   
                      {   
                              currPage   =   1;   
                              PrintDocument   doc   =   new   PrintDocument();   
                              doc.DocumentName   =   fileName;   
                              doc.PrintPage   +=   new   PrintPageEventHandler(PrintPageEvent);   
                              return   doc;   
                      }   
        
                      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;   
                      }   
              }   
      }   
      
      

  2.   

    if   (textBox1.Text   !=   string.Empty)   
                              {   
                                      TextFilePrinter   tfp   =   new   TextFilePrinter(m_strTxtPath);   
                                      tfp.Print();   
                              }   
        
      调用方法。   
      

  3.   

    http://www.jobdll.com/user/gt/log/2274.html