在C#中如何实现打印功能呢?比如我有个文本在richtextbox中我只想打印richtextbox里面的内容如何实现这个功能呢如何使用printdialog和printpreviewdialog怎么才可以呢

解决方案 »

  1.   

    请参考:
    http://topic.csdn.net/u/20091129/20/0ff4234a-038e-485e-8e35-15820d4e8648.html
    第7,8楼。
      

  2.   


          private void button1_Click(object sender, EventArgs e)
            {            System.Drawing.Printing.PrintDocument pd=new System.Drawing.Printing.PrintDocument();
                pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
                pd.Print();
            }        void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                Single ypos = 0;
                Single leftmargin = e.MarginBounds.Left;
                Single topmargin = e.MarginBounds.Top;            Single x=leftmargin;
                e.Graphics.DrawString(this.richTextBox1.Text,
                                        new System.Drawing.Font("宋体", 10),
                                         System.Drawing.Brushes.Black, x, ypos,
                                         new System.Drawing.StringFormat());            e.HasMorePages = false;
            }