Print Preview and Print functionality Code in Windows C# application

Posted by Raj.Trivedi under C# category on | Points: 40 | Views : 39788
Hello Friends,

Drag and Drop PrintDialog ,Print Preview Dialog box and print document on the window form.

Add the namespace to your code behind.

using System.Drawing.Printing;

This name space will allow us to use print functionality.

// This will call the print dialog box to select the printer.

private void printToolStripMenuItem_Click(object sender, EventArgs e)

printDialog1.Document = printDocument;

if (printDialog1.ShowDialog() == DialogResult.OK)

// This will allow us to see print preview before printing.

private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
printPreviewDialog1.Document = printDocument;


// This will send the Rich Text Box data to print.
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
e.Graphics.DrawString(richTextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 20);
e.Graphics.PageUnit = GraphicsUnit.Inch;

Comments or Responses

Login to post response