Introducing PrintDocument Controls
<summary>
Printing method
</summary>
public void Print ()
{
Instantiating a Print object
PrintDocument printDocument1 = new PrintDocument ();
Set the paper for printing, and when set to custom, you can customize the size of the paper
PrintDocument1.DefaultPageSettings.PaperSize = new PaperSize ("Custum", 420, (Printdata.count * 155) + (Printdata.count * 10) + 10);
Registers the PrintPage event, which is triggered when each page is printed
Printdocument1.printpage + = new Printpageeventhandler (this.printdocument1_printpage);
Initializing the Print Preview dialog box object
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog ();
Assign a PrintDocument1 object to the document property of the Print Preview dialog box
Printpreviewdialog1.document = PrintDocument1;
Open the Print Preview dialog box
DialogResult result = Printpreviewdialog1.showdialog ();
if (result = = DialogResult.OK)
{
Printdocument1.print ();//Start printing the PrintPage event for the--printdocument control
}
}
PrintPage Events for PrintDocument controls
private void Printdocument1_printpage (object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Draw the printed content
E.graphics.drawstring ("Wu Shijie", New System.Drawing.Font ("Arial", 6, FontStyle.Bold), New SolidBrush (Color.Black), new PointF (5, 53));
}
C#winfrom Print and print preview