示例#1
0
        /// <summary>
        /// 打印富文本内容
        /// </summary>
        /// <param name="printDocument">打印文档</param>
        /// <param name="preview">预览对象</param>
        public void PrintRTF(PrintDocument printDocument, bool preview)
        {
            try
            {
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument_BeginPrint);
                printDocument.EndPrint   += new System.Drawing.Printing.PrintEventHandler(this.printDocument_EndPrint);
                printDocument.PrintPage  += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument_PrintPage);

                CoolPrintPreviewDialog dlg = new CoolPrintPreviewDialog();
                dlg.Document = printDocument;
                if (preview)
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        printDocument.Print();
                    }
                }
                else
                {
                    printDocument.Print();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }