C # Custom Print class program in asp.net

Source: Internet
Author: User
The code is as follows Copy 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 + @ "resourcelogo.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 ( "Song Body", 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 ( "Song Body", 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 ("XXFarEastFont-Arial", fontstyle.bold);
Printtxt = "Thank You";
E.graphics.drawstring (Printtxt, Strfont, Brushes.black, 12, 481);
Strfont = new Font ("Song Body", 8);
Printtxt = DateTime.Now.ToString ("mm/dd/yyyy hh:mmt\m");
E.graphics.drawstring (Printtxt, Strfont, Brushes.black, 184, 487);

           }
       }

        public void PrintDocument ()
         {
            document. Defaultpagesettings.papersize = new PaperSize ("Custum", PageWidth, PageHeight);
            Printcontroller Printcontroller = new Standardprintcontroller ();
            document. Printcontroller = Printcontroller;
           // System.Windows.Forms.PrintPreviewDialog PrintPreview = new System.Windows.Forms.PrintPreviewDialog ();
           //printpreview.document = Document;
           //printpreview.showdialog ();

            document. Print ();
       }

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.