public void ReadFile() { documentContents = File.ReadAllText(FilePath); stringToPrint = documentContents; } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int charactersOnPage = 0; int linesPerPage = 0; e.Graphics.MeasureString(stringToPrint, this.Font, e.MarginBounds.Size, StringFormat.GenericTypographic, out charactersOnPage, out linesPerPage); e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black, 110,10); stringToPrint = stringToPrint.Substring(charactersOnPage); e.HasMorePages = (stringToPrint.Length > 0); if (!e.HasMorePages) stringToPrint = documentContents; } private void btnPreview_Click(object sender, EventArgs e) { ReadFile(); printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)