StreamReader streamToPrint = new StreamReader ("PrintMe.Txt");
    try {
        TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint);        if (storedPageSettings != null) {
            pd.DefaultPageSettings = storedPageSettings ;
        }        PrintPreviewDialog dlg = new PrintPreviewDialog() ;
        dlg.Document = pd;
        dlg.ShowDialog();    } finally {
        streamToPrint.Close() ;
    }//TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint);什么意思啊。怎么在调试的时候说没有TextFilePrintDocument

解决方案 »

  1.   

    系统本身没,TextFilePrintDocument类,你写了这个类了没有?public class TextFilePrintDocument : PrintDocument {    private Font printFont           = null ;
        private StreamReader streamToPrint = null ;    public TextFilePrintDocument(StreamReader streamToPrint) : base ()  {
            this.streamToPrint = streamToPrint ;
        }    //Override OnBeginPrint to set up the font we are going to use
        protected override void OnBeginPrint(PrintEventArgs ev) {
            base.OnBeginPrint(ev) ;
            printFont = new Font("Arial", 10);
        }    //Override the OnPrintPage to provide the printing logic for the document
        protected override void OnPrintPage(PrintPageEventArgs ev) {        base.OnPrintPage(ev) ;        float lpp = 0 ;
            float yPos =  0 ;
            int count = 0 ;
            float leftMargin = ev.MarginBounds.Left;
            float topMargin = ev.MarginBounds.Top;
            String line=null;        //Work out the number of lines per page 
            //Use the MarginBounds on the event to do this 
            lpp = ev.MarginBounds.Height  / printFont.GetHeight(ev.Graphics) ;        //Now iterate over the file printing out each line
            //NOTE WELL: This assumes that a single line is not wider than the page width
            //Check count first so that we don't read line that we won't print
            while (count < lpp && ((line=streamToPrint.ReadLine()) != null)) {
                yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));            //Print Preview control will not work.
                ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin,
                                        yPos, new StringFormat());            count++;
            }        //If we have more lines then print another page
            if (line != null)
                ev.HasMorePages = true ;
            else
                ev.HasMorePages = false ;
        }}
      

  2.   

    I know your code from this site http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsPrinting.aspxYou haven't  get all of them down, but apart of them
      

  3.   

    get  -> gotten  English syntax error
      

  4.   

    使用这个开源免费的打印
    http://community.csdn.net/Expert/topic/3278/3278050.xml?temp=.5012934下载
    www.alinksoft.com打印对话框的文章
    http://blog.csdn.net/error.aspx?aspxerrorpath=/flygoldfish/archive/2004/08/17/77208.aspx