1. Page Setup (PageSetupDialog)
Pagesetupdialog1.document = PrintDocument1; You must set the Print object, otherwise you do not know who to print
Pagesetupdialog1.showdialog (); ShowDialog is the way to print this column.
Execution Result:
2. Printing ()
To execute code when you click Print:
private void Button2_Click (object sender, EventArgs e)
{
Printdialog1.document = PrintDocument1;
DialogResult dr= Printdialog1.showdialog (); Determine whether the clicked button is OK or canceled
if (dr = = DialogResult.OK)//If it is OK to print
{
Printdocument1.print ();
}
}
Print Object PrintDocument trigger event
private void Printdocument1_printpage (object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Font f=new System.Drawing.Font ("Song Body", 12); Objects that create System.Drawing.Font font types
E.graphics.drawstring (textbox1.text,f,system.drawing.brushes.aquamarine,10,10);
}
Execution Result:
1. Click Print: 2. Printing results:
March 18 WinForm Page setup and printing