C# 自定义打印模版

用微软自带五件套

           

//定义边界 设置纸张大小 注意 335  (纸张的宽度,以百分之一英寸为单位)

            Margins margin = new Margins(0, 0, 0, 0);
            printDocument1 = new PrintDocument();
            printDocument1.DefaultPageSettings.Margins = margin;
            printDocument1.DefaultPageSettings.PaperSize = new PaperSize("热敏纸", 355, 119);
            printDocument1.PrintPage += new PrintPageEventHandler(PrintPageEvent);
            printDocument1.PrintController = controler;
            printDocument1.Print(); 

public void PrintPageEvent(object Sender, PrintPageEventArgs e)
        {
            //设置字体样式
            Font titleFont = new Font("黑体", 44, System.Drawing.FontStyle.Bold);//标题字体           
            Font fntTxt = new Font("宋体", 11, System.Drawing.FontStyle.Underline);//正文带下划线        
            Font smallFont = new Font("宋体", 8, System.Drawing.FontStyle.Underline);//正文带下划线        
            Font smallFont1 = new Font("宋体", 8, System.Drawing.FontStyle.Underline);//正文带下划线      
            Font smallFont2 = new Font("宋体", 11, System.Drawing.FontStyle.Underline);//正文带下划线         
            Font fntTxt1 = new Font("宋体", 11, System.Drawing.FontStyle.Regular);//正文文字           
            System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);//画刷           
            System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);

           //根据位置画文字

            e.Graphics.DrawString("标识", fntTxt1, brush, new System.Drawing.Point(3, 8));
            e.Graphics.DrawString("名称", fntTxt1, brush, new System.Drawing.Point(3, 36));
            e.Graphics.DrawString("型号", fntTxt1, brush, new System.Drawing.Point(3, 64));
            e.Graphics.DrawString("日期", fntTxt1, brush, new System.Drawing.Point(3, 92));


            if (_xfbsh.Length > 29)
            {
                smallFont2 = new Font("宋体", 8, System.Drawing.FontStyle.Regular);//正文文字   
            }

            //if (_cpmc.Length > 29)
            //{
            //    smallFont = new Font("宋体", 8, System.Drawing.FontStyle.Regular);//正文文字   
            //}

            //if (_ggxh.Length > 29)
            //{
            //    smallFont1 = new Font("宋体", 8, System.Drawing.FontStyle.Regular);//正文文字   
            //}

            e.Graphics.DrawString(_xfbsh, smallFont2, brush, new System.Drawing.Point(40, 8));
            e.Graphics.DrawString(_cpmc, smallFont, brush, new System.Drawing.Point(40, 36));
            // e.Graphics.DrawString(_ggxh, smallFont1, brush, new System.Drawing.Point(40, 64));

            RectangleF descRect = new RectangleF();
            using (Font useFont = new Font("宋体", 8, System.Drawing.FontStyle.Regular))
            {
                descRect.Location = new Point(40, 64);
                descRect.Size = new Size(240, 40);
                e.Graphics.DrawString(_ggxh, smallFont1, Brushes.Black, descRect);
            }

            e.Graphics.DrawString(_scrq, fntTxt, brush, new System.Drawing.Point(40, 92));

            Bitmap bitmap = CreateQRCode(_cCode);
            e.Graphics.DrawImage(bitmap, 275, 8, 60, 60);

            e.Graphics.DrawString(_dw, fntTxt1, brush, new System.Drawing.Point(240, 92));
            //  e.Graphics.DrawImage(bitmap, new System.Drawing.Point(70, 2));
        }

效果图

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值