zoukankan      html  css  js  c++  java
  • C# 打印机

       private void printDocument_PrintPage(object sender, PrintPageEventArgs ev)
            {

                Font titleFont = new Font("宋体", 9, FontStyle.Bold);//标题字体           

                Font fntTxt = new Font("宋体", 9, FontStyle.Regular);//正文文字           

                Brush brush = new SolidBrush(Color.Black);//画刷           

                Pen pen = new Pen(Color.Black);           //线条颜色           

                Point po = new Point(10, 10);

                try
                {

                    ev.Graphics.DrawString(GetPrintSW().ToString(), titleFont, brush, po);   //DrawString方式进行打印。        

                }

                catch (Exception ex)
                {

                    MessageBox.Show(this, "打印出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

            }

            ///GetPrintSw方法用来构造打印文本,内部StringBuilder.AppendLine在Drawstring时单独占有一行。

            public StringBuilder GetPrintSW()
            {

                StringBuilder sb = new StringBuilder();

                string tou = "测试管理公司名称";

                string address = "河南洛阳";

                string saleID = "2010930233330";    //单号       

                string item = "项目";

                decimal price = 25.00M;

                int count = 5;

                decimal total = 0.00M;

                decimal fukuan = 500.00M;

                sb.AppendLine(" " + tou + " ");

                sb.AppendLine("-----------------------------------------");

                sb.AppendLine("日期:" + DateTime.Now.ToShortDateString() + " " + "单号:" + saleID);

                sb.AppendLine("-----------------------------------------");

                sb.AppendLine("项目" + "      " + "数量" + "    " + "单价" + "    " + "小计");

                for (int i = 0; i < count; i++)
                {

                    decimal xiaoji = (i + 1) * price;

                    sb.AppendLine(item + (i + 1) + "      " + (i + 1) + "     " + price + "    " + xiaoji);

                    total += xiaoji;

                }

                sb.AppendLine("-----------------------------------------");

                sb.AppendLine("数量:" + count + "  合计: " + total);

                sb.AppendLine("付款:" + fukuan);

                sb.AppendLine("现金找零:" + (fukuan - total));

                sb.AppendLine("-----------------------------------------");

                sb.AppendLine("地址:" + address + "");

                sb.AppendLine("电话:123456789 123456789");

                sb.AppendLine("谢谢惠顾欢迎下次光临 ");

                sb.AppendLine("-----------------------------------------");

                return sb;

            }

    触发事件

        private void btnPrint_Click(object sender, EventArgs e)
            {
                pd.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); //打印页面需指定相应的PrintDocument_PrintPrintPage事件委托     

                pd.Print();

            }

  • 相关阅读:
    第十一次作业
    第十次作业
    第九次作业
    第八次作业
    第七次作业
    第六次作业
    Springboot 2.x 使用 Druid 数据源
    @ConditionalOnMissingBean、@Import 组合使用
    Springboot 2.x 整合 JDBC
    IDEA org.apache.maven.plugins:maven-jar-plugin 报红
  • 原文地址:https://www.cnblogs.com/http-www/p/3578842.html
Copyright © 2011-2022 走看看