March 18 WinForm Page setup and printing

Source: Internet
Author: User
Tags print object

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

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.