Test print function

Source: Internet
Author: User

Create a form, pull in a button control two, a preview feature, a print function, and then pull the control PrintDocument control, Printpreviewdilogs control, Pagesetupdilogs control

Background code

1 list<string> students =New list<String> () {"Tom","John doe","Harry"};2int count =0;//Subscript value for the learner name to be printed3Privatevoid Printdocument1_printpage (Objectsender, System.Drawing.Printing.PrintPageEventArgs e)4{5 Graphics g =E.graphics;6String name =Students[count];7 g.drawstring (name,New Font ("Song Body",), Brushes.black,100,100);8//G.drawline (New Pen (color.red), new Point (200,200), new Point (300,200));9G.dispose ();Ten count++;//Increment, in order to print the next name11//Determine if the print is finished12if (count = =Students. Count)13{E.hasmorepages =False//Do not print next page15}16Else17{E.hasmorepages =True//Continue to print next page19}20}21st22//Preview button23Privatevoid Btnprev_click (Objectsender, EventArgs e)24{25This.printPreviewDialog1.Document =This. printDocument1;26This. Printpreviewdialog1.showdialog ();27}2829//Print button30Privatevoid Btnprint_click (object sender, EventArgs e) 31  {32 this.pagesetupdialog1.document = this33 if ( This.pageSetupDialog1.ShowDialog () == System.Windows.Forms.DialogResult.OK) 34  {35 // print 36 }37}            

Test print function

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.