C#winfrom Print and print preview

Source: Internet
Author: User
Tags print object

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.