ZXing.Net条形码二维码标签编辑打印软件

 

 

ZXing.Net条形码二维码打印软件

C#打印 1.建立PrintDocument对象2.设置PrintPage打印事件3.调用Print方法进行打印

Microsoft .NET Framework 4.5

ZXing.Net

BarcodeWriter用于生成图片格式的条码类,通过Write函数进行输出
BarcodeFormat枚举类型,条形码/二维码
QrCodeEncodingOptions二维码设置选项,继承于EncodingOptions,主要设置宽,高,编码方式等
MultiFormatWriter复合格式条码写码器,通过encode方法得到BitMatrix
BitMatrix表示按位表示的二维矩阵数组,元素的值用true和false表示二进制中的1和0

 

 

 

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing;
using ZXing.QrCode;

namespace KopSoftPrint
{
    internal class QRCode
    {
        public void GenerateQRCode(string contents, PictureBox qrimage)
        {
            BarcodeWriter barcodeWriter = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    DisableECI = true,
                    CharacterSet = "UTF-8",
                    Width = qrimage.Width,
                    Height = qrimage.Height,
                    Margin = 1 //二维码边距
                }
            };

            Bitmap bitmap = barcodeWriter.Write(contents);
            qrimage.Image = bitmap;
        }
    }
}
View Code
        public void Print(int Number)
        {
            pd.DefaultPageSettings.PaperSize = new PaperSize("", 999, 999); //设置纸张大小
            StandardPrintController controler = new StandardPrintController();

            if (dataGridView1.CurrentCell != null)
            {
                for (int j = 0; j < dataGridView1.SelectedRows.Count; j++) //遍历所有选中的行
                {
                    rowIndex = dataGridView1.SelectedRows[j].Index;
                    try
                    {
                        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                        pd.PrintController = controler;
                        for (int i = 0; i < Number; i++)
                        {
                            pd.Print();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                    finally
                    {
                        pd.Dispose();
                    }
                }
            }
        }
View Code

 

 

加强版地址 https://www.cnblogs.com/williamyoung/p/10752970.html

 

转载于:https://www.cnblogs.com/williamyoung/p/10535198.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值