码迷,mamicode.com
首页 > Windows程序 > 详细

winform 打印小票

时间:2015-03-30 06:44:30      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

后台代码

技术分享
 1   panPrintContent.Visible = true;
 2             var strlPrinterMode = "";
 3 
 4             this.pageSetupDialog1.PageSettings.Margins.Left = 1;
 5             this.pageSetupDialog1.PageSettings.Margins.Top = 1;
 6             this.pageSetupDialog1.PageSettings.Margins.Right = 21;
 7             this.pageSetupDialog1.PageSettings.Margins.Bottom = 21;
 8             panPrintContent.Visible = true;
 9 
10             //打印设置
11             try
12             {
13                 string sqls = "select PrinterMode from User_Org where UserID=‘" + DBCommonServer.strUserName + "‘ and OID=‘" + DBCommonServer.strOrgId + "";
14                 DataTable dt1 = helps.GetDataTable(sqls);
15                 if (dt == null)
16                 {
17                     return;
18                 }
19                 if (dt1.Rows.Count > 0)
20                 {
21                     strlPrinterMode = dt1.Rows[0][0].ToString();
22                 }
23                 if (strlPrinterMode == "0")
24                 {
25                     this.printPreviewDialog1.ShowDialog();
26                 }
27                 else
28                 {
29                     for (int i = 0; i < Convert.ToInt32(strlPrinterMode); i++)
30                     {
31                         
32                         this.printDocument1.Print();
33                     }
34                 }
35             }
36             catch (Exception)
37             {
38                 MessageBox.Show("您好!您的电脑有可能打印服务没有启动或是没有安装打印机。"
39                                  + Environment.NewLine + Environment.NewLine + "请先启动打印服务或是安装打印机!");
40             }
View Code
技术分享
 1  /// <summary>
 2        /// 打印内容
 3        /// </summary>
 4        /// <param name="sender"></param>
 5        /// <param name="e"></param>
 6         private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
 7         {
 8             ////打印内容 为 局部的 this.groupBox1
 9             Bitmap _NewBitmap = new Bitmap(this.panPrintContent.Width, this.panPrintContent.Height);
10             this.panPrintContent.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
11             e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);
12         }
View Code

动态获得控件

技术分享
 1   int iheight = iLabHeight * i;
 2                     Label LlabPrintPayType = new Label();
 3                     LlabPrintPayType.Name = "LlabPrintPayType" + i;
 4                     //  LlabPrintPayType.Location = new Point(ilabPrintPayType_X, ilabPrintPayType_Y + iheight);
 5                     LlabPrintPayType.Location = new Point(25,i*20+20);
 6                     LlabPrintPayType.Text = dtlistPay.Rows[i]["付款方式名称"].ToString() + (dtlistPay.Rows[i]["卡号"].ToString() == "" ? "" : "(" + dtlistPay.Rows[i]["卡号"].ToString() + ")");
 7                     LlabPrintPayType.Height = 20;
 8                     panFkfs.Controls.Add(LlabPrintPayType);
 9                     Label LlabPrintCost = new Label();
10                     LlabPrintCost.Name = "LlabPrintCost" + i;
11                     LlabPrintCost.Location = new Point(170, i * 20 + 20);
12                     string strPrintCost = decimal.Round(Convert.ToDecimal(dtlistPay.Rows[i]["金额"].ToString()), 2, MidpointRounding.AwayFromZero).ToString();
View Code

 

前台代码

技术分享

 

技术分享

 

winform 打印小票

标签:

原文地址:http://www.cnblogs.com/yuanjiehot/p/4377008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!