Step1: Associate control to Print document
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(richTextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 20);
e.Graphics.PageUnit = GraphicsUnit.Inch;
}
Step2: write code for printing and print preview.
private void btnPrint_Click(object sender, EventArgs e)
{
//PrintDialog associate with PrintDocument;
printDialog1.Document = printDocument1;
if (printDialog1.ShowDialog()==DialogResult.OK)
{
printDocument1.Print();
}
}
private void btnPrintPreview_Click(object sender, EventArgs e)
{
//Associate PrintPreviewDialog with PrintDocument.
printPreviewDialog1.Document = printDocument1;
// Show PrintPreview Dialog
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(richTextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 20);
e.Graphics.PageUnit = GraphicsUnit.Inch;
}
Step2: write code for printing and print preview.
private void btnPrint_Click(object sender, EventArgs e)
{
//PrintDialog associate with PrintDocument;
printDialog1.Document = printDocument1;
if (printDialog1.ShowDialog()==DialogResult.OK)
{
printDocument1.Print();
}
}
private void btnPrintPreview_Click(object sender, EventArgs e)
{
//Associate PrintPreviewDialog with PrintDocument.
printPreviewDialog1.Document = printDocument1;
// Show PrintPreview Dialog
printPreviewDialog1.ShowDialog();
}
No comments:
Post a Comment