private void printReceipt() { printDialog.Document = printDocument; DialogResult result = printDialog.ShowDialog(); if (result != DialogResult.OK) return; try { sPrint = new StreamReader( new MemoryStream( Encoding.ASCII.GetBytes(richTextBoxResult.Text))); printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); printDocument.Print(); } catch (Exception e) { MessageBox.Show("Failed to print \n" + e.Message); } finally { if (sPrint != null) sPrint.Close(); } } void printDocument_PrintPage(object sender, PrintPageEventArgs e) { // No of lines that fit on to the page float linesPerPage = e.MarginBounds.Height / richTextBoxResult.Font.GetHeight(e.Graphics); float fontHeight = richTextBoxResult.Font.GetHeight(e.Graphics); for (int count = 0; count < linesPerPage && !sPrint.EndOfStream; count++) { e.Graphics.DrawString(sPrint.ReadLine(), richTextBoxResult.Font, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top + (count * fontHeight), new StringFormat()); } e.HasMorePages = !sPrint.EndOfStream; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)