Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the specific implementation of the C # print source code?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about the specific implementation of the C# printing source code, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.

C# print source code is also one of the functions of the print control. The C# print source code introduced here can achieve automatic printing processing, but it needs the support of mdi files.

The principle of printing is: the mdi file is generated, and when the system encounters mdi, it will automatically print the file. So, no matter what template or method you use, it's OK to generate a picture of what you want to print in PrintPage event handling!

The C# print source code is as follows:

# region print private void btnPrint_Click (object sender, EventArgs e) {/ / print Preview / / PrintPreviewDialog ppd = new PrintPreviewDialog (); PrintDocument pd = new PrintDocument (); / / set margins Margins margin = new Margins (20, 20, 20); pd.DefaultPageSettings.Margins = margin / Paper setting default / / PaperSize pageSize = new PaperSize ("First custom size", 800,600); / / pd.DefaultPageSettings.PaperSize = pageSize; / / print event setting pd.PrintPage + = new PrintPageEventHandler (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, new PrintEventArgs ()) }} / / print event handling private void pd_PrintPage (object sender, PrintPageEventArgs e) {string date = lblDate.Text; / / current date string flowId = lblFlowId.Text; / / serial number string payDate = PayDate.Year.ToString () + "year" + PayDate.Month.ToString () + "month" / / year / month receivable string adminId = lblAdminId.Text; / / operator No. String baseExpense = lblBaseExpense.Text; / / basic fee payable string fine = lblFine.Text; / / number of fines string upExpense = lblUpExpense.Text; / / the last month remaining string actualExpense = txtActualExpense.Text / / actual fee payable string chineseExpense = DecimalToChinese.ConvertSum (actualExpense); / / Chinese capitalization of actual fee payable / / read picture template Image temp = Image.FromFile (@ "Receipts.jpg"); GetResultIntoImage (ref temp, UserId, flowId, date, baseExpense, fine, upExpense, actualExpense, chineseExpense, payDate, adminId); int x = e.MarginBounds.X Int y = e.Marginbounds.Y; int width = temp.Width; int height = temp.Height; Rectangle destRect = new Rectangle (x, y, width, height); e.Graphics.DrawImage (temp, destRect, 0,0, temp.Width, temp.Height, System.Drawing.GraphicsUnit.Pixel) } / populate the charging result into the image template / private void GetResultIntoImage (ref Image temp, string userId, string flowId, string currentDate, string baseExpense, string fine, string upExpense) String actualExpense, string chineseExpense, string payDate, string adminName) {/ / read picture template Graphics g = Graphics.FromImage (temp) Font f = new Font ("Arial", 12); Brush b = new SolidBrush (Color.Black); / / fill data into the picture template (location should be measured when making the picture template) g.DrawImage (temp, 0, 0, temp.Width, temp.Height); g.DrawString (userId, f, b, 168,105) G.DrawString (UserName, f, b, 166,134); g.DrawString (flowId, f, b, 535,105); 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, 176269); g.DrawString (adminName, f, b, 497,298); g.Dispose () } # endregion above is the specific implementation of the C# print source code. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report