C # custom Printing

Source: Internet
Author: User

C # custom printing class, which can print text, lines, images, etc. The following is just an example:Code:

 Public   Class  Printinfo {  Public   String Portname { Get ; Set  ;}  Public   String Departuretime { Get ; Set  ;}  Public  String Ampm { Get ; Set  ;}  Printdocument document = New  Printdocument ();  Private   Int Pagewidth = 302  ;  Private   Int Pageheight = 530  ; Public  Printinfo (){
Portname = "test port ";
Departuretime = "11: 30 ";
Ampm = "Morning"; document. beginprint + = New Printeventhandler (document_beginprint); document. printpage + = New Printpageeventhandler (document_printpage); document. endprint + = New Printeventhandler (document_endprint );} Private Void Document_endprint (Object Sender, printeventargs e ){} Private Void Document_beginprint ( Object Sender, printeventargs e ){} Private Void Document_printpage ( Object Sender, system. Drawing. Printing. printpageeventargs e ){ If (Departuretime! = Null ){ // Logo Bitmap imagelogo = New Bitmap (system. appdomain. currentdomain. basedirectory + @" \ Resource \ logo.bmp " ); E. Graphics. interpolationmode = Interpolationmode. highqualitybicubic; E. Graphics. smoothingmode = Smoothingmode. highquality; E. Graphics. compositingquality =Compositingquality. highquality; E. Graphics. drawimage (imagelogo, 5 , 10 , 292 , 131 ); // Line E. Graphics. drawline ( New Pen (brushes. Black, 3 ), 12 , 166 , 291 ,166 ); // Port name Font strfont = New Font ( " " , 18 ); E. Graphics. drawstring (portname, strfont, brushes. Black ,( Float ) Pagewidth/ 2 -E. Graphics. measurestring (portname, strfont). width/ 2 +1 , 198 ); // Departure time Strfont = New Font ( " " , 50 , Fontstyle. Bold); E. Graphics. drawstring (departuretime, strfont, brushes. Black ,( Float ) Pagewidth/ 2 -E. Graphics. measurestring (departuretime, strfont). width/ 2 , 248 ); // Ampm E. Graphics. drawstring (ampm, strfont, brushes. Black ,( Float ) Pagewidth/ 2 -E. Graphics. measurestring (ampm, strfont). width/ 2 , 320 ); // Line E. Graphics. drawline ( New Pen (brushes. Black, 3 ), 12 , 419 , 291 , 419 ); // Thankyou and print time Strfont = New Font ( " " , 13 , Fontstyle. Bold); printtxt = " Thank you " ; E. Graphics. drawstring (printtxt, strfont, brushes. Black, 12 , 481 ); Strfont = New Font ( " " , 8 ); Printtxt = Datetime. Now. tostring ( " Mm/DD/YYYY hh: MT \ m " ); E. Graphics. drawstring (printtxt, strfont, brushes. Black, 184 , 487 );}} Public Void Printdocument () {document. defaultpagesettings. papersize = New Papersize ( " Custum " , Pagewidth, pageheight); printcontroller = New Standardprintcontroller (); document. printcontroller = Printcontroller; // System. Windows. Forms. printpreviewdialog printpreview = new system. Windows. Forms. printpreviewdialog (); // Printpreview. Document = document; // Printpreview. showdialog (); Document. Print ();}

 

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.