C # Print Pictures

Source: Internet
Author: User

The principle of printing is to generate MDI files that are automatically processed when the system touches the MDI. So, no matter what template, what way; in PrintPage event processing, generate a picture to print the content is OK!

C # Implementation of the printed source code is as follows:

#regionPrint
PrivatevoidBtnprint_click (Objectsender, EventArgs e)
{
//Print Preview
//PrintPreviewDialog ppd = new PrintPreviewDialog ();
PrintDocument PD =NewPrintDocument ();
//Set Margins
Margins margin =NewMargins ( -, -, -, -);
Pd. Defaultpagesettings.margins = margin;
////paper Settings default
//PaperSize pageSize = new PaperSize ("First Custom Size", 800, 600);
//PD. Defaultpagesettings.papersize = pageSize;
//Print Event Settings
Pd. PrintPage + =NewPrintpageeventhandler ( This. pd_printpage);
//PPD. Document = PD;
//PPD. ShowDialog ();
Try
{
Pd. Print ();
}
Catch(Exception ex)
{
MessageBox.Show (ex. Message,"Print Error", MessageBoxButtons.OK, Messageboxicon.error);
Pd. Printcontroller.onendprint (PD,NewPrintEventArgs ());
}
}
//Print Event Handling
Privatevoidpd_PrintPage (Objectsender, PrintPageEventArgs e)
{
stringdate = Lbldate.text;//Current Date
stringFlowid = Lblflowid.text;//Serial Number
stringPayDate = PayDate.Year.ToString () +"years"+ PayDate.Month.ToString () +"Month";//Date Receivable
stringAdminid = Lbladminid.text;//operator Number
stringBaseexpense = Lblbaseexpense.text;//Basic Fees payable
stringfine = Lblfine.text;//Number of fines
stringUpexpense = Lblupexpense.text;//Last month's more
stringActualexpense = Txtactualexpense.text;//The actual fee should be used
stringChineseexpense = Decimaltochinese.convertsum (actualexpense);//Chinese capitalization for actual fee

//reading a picture template
Image temp = Image.FromFile (@"receipts.jpg");
Getresultintoimage (refTemp, UserId, Flowid, date, Baseexpense, fine, Upexpense, Actualexpense, Chineseexpense, PayDate, Adminid);
intx = e.marginbounds.x;
inty = e.marginbounds.y;
intwidth = temp. Width;
intHeight = temp. Height;
Rectangle Destrect =NewRectangle (x, y, width, height);
E.graphics.drawimage (temp, destrect,0,0, temp. Width, temp. Height, System.Drawing.GraphicsUnit.Pixel);
}

/// <summary>
///fill in the result of the charge to the picture template
/// </summary>
PrivatevoidGetresultintoimage (
refImage temp,
stringUserid
stringFlowid,
stringcurrentdate,
stringBaseexpense,
stringFine
stringUpexpense,
stringActualexpense,
stringChineseexpense,
stringPayDate,
stringAdminName)
{
//reading a picture template
Graphics g = graphics.fromimage (temp);

Font f =NewFont ("Song Body", A);
Brush B =NewSolidBrush (Color.Black);

//fill the data to the picture template (the position should be measured when making the picture template)
G.drawimage (temp,0,0, temp. Width, temp. Height);
g.DrawString (UserId, F, B,168, the);
g.DrawString (UserName, F, B,166,134);
g.DrawString (Flowid, F, B,535, the);
g.DrawString (currentdate, F, B,535,134);
g.DrawString (Baseexpense, F, B,219,202);
g.DrawString (fine, F, B,372,202);
g.DrawString (Upexpense, F, B,486,202);
g.DrawString (Actualexpense, F, B,596,202);
g.DrawString (Chineseexpense, F, B,196,238);
g.DrawString (PayDate, F, B,176,269);
g.DrawString (AdminName, F, B,497,298);

G.dispose ();
}
#endregion

Turn from: http://hi.baidu.com/zhaogaoyan8/blog/item/d50fbf9a3f66c0bdc9eaf4c7.html

C # Print Pictures

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.