Printdocument control (favorites)

Source: Internet
Author: User

The printdocument control sets the printed document. In the printdocument control, the printpage event and print method of the control are common. The printpage event occurs when the output of the current page needs to be printed. Call the print method to start the document printing process. The following example shows how to use the printdocument control.
For example, create a Windows application and add a button control, a printdocument control, and a printpreviewdialog control to the form. In the printpage event of the printdocument control, draw the printed content, set the printpreviewdialog attribute under the Click Event of the button to preview the printed document, and call the print method of the printdocument control to start the printing process of the document, the Code is as follows.

Private void printdocumentemediprintpage (Object sender, system. Drawing. Printing. printpageeventargs E)
{
// Draw and print the document through GDI +
E. Graphics. drawstring ("Butterfly", new font ("", 15), brushes. Black, 350, 80 );
E. Graphics. drawline (new pen (color. Black, (float) 3.00), 100,185,720,185 );
E. Graphics. drawstring. ", New font (" ", 12), brushes. Black, 110,195 );
E. Graphics. drawstring. ", New font (" ", 12), brushes. Black, 110,220 );
E. Graphics. drawstring ("it is intended to get the crazy figure drunk. It is boring to play with wine. ", New font (" ", 12), brushes. Black, 110,245 );
E. Graphics. drawstring ("I don't regret it. It's embarrassing for Iraq. ", New font (" ", 12), brushes. Black, 110,270 );
E. Graphics. drawline (new pen (color. Black, (float) 3.00), 100,300,720,300 );

}

Click the button to view the current event

 

Private void button#click (Object sender, eventargs E)
{
If (MessageBox. Show ("whether to preview printed documents", "print preview", messageboxbuttons. yesno) = dialogresult. Yes)
{
// Enable the anti-tooth feature of the Operating System
This. printpreviewdialog1.useantialias = true;
// Set the document to be previewed
This. printpreviewdialog1.document = This. printdocument1;
// Open the preview window
Printpreviewdialog1.showdialog ();
}
Else
{
// Call the print method to print the document directly
// This. printdocument1.print ();
}

}

 

 

 

Run the program and click "print" to bring up the "print preview" form ,.


 

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.