// Print Event private void miPrint_Click(object sender, System.EventArgs e) { if (printDialog1.ShowDialog() == DialogResult.OK) { // printDocument1.DefaultPageSettings.PaperSize.Width = 9000; printDocument1.Print(); } } // OnBeginPrint private void OnBeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e) { char[] param = {'\n'}; PrinterSettings p = new PrinterSettings(); PaperSize ps = new PaperSize ("Custom",9000,90000); printDocument1.DefaultPageSettings.PaperSize = ps; if (printDialog1.PrinterSettings.PrintRange == PrintRange.Selection) { lines = richTextBox1.SelectedText.Split(param); } else { lines = richTextBox1.Text.Split(param); } int i = 0; char[] trimParam = {'\r'}; foreach (string s in lines) { lines[i++] = s.TrimEnd(trimParam); } } // OnPrintPage private void OnPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int x = e.MarginBounds.Left; int y = e.MarginBounds.Top; Brush brush = new SolidBrush(richTextBox1.ForeColor); while (linesPrinted < lines.Length) { e.Graphics.DrawString (lines[linesPrinted++], richTextBox1.Font, brush, x, y); y += 15; if (y >= e.MarginBounds.Bottom) { e.HasMorePages = true; return; } } linesPrinted = 0; e.HasMorePages = false; } // Page Setup private void miSetup_Click(object sender, System.EventArgs e) { // Call Dialog Box pageSetupDialog1.ShowDialog(); } // Print Preview private void miPreview_Click(object sender, System.EventArgs e) { // Call Dialog Box printPreviewDialog1.ShowDialog(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)