1 打印效果

2 生成二维码和条形码的dll
条码和二维码生成的DLL
3 二维码生成类QRcodeCreator
using ThoughtWorks.QRCode.Codec;
namespace LotteryPro
{
    public class QRcodeCreator
    {
        #region 根据链接生成二维码
        
        
        
        
        
        public static Image GetQRCodeBmp(string url)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeScale = 4;
            qrCodeEncoder.QRCodeVersion =0;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            return qrCodeEncoder.Encode(url);
        }
        #endregion
    }
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
4 打印彩票方法编写
public void PrintLottery(System.Drawing.Printing.PrintPageEventArgs e, string serialNum, List<string> numList)
{
    
    Fath.BarcodeX barCode = new Fath.BarcodeX();
    barCode.Text = serialNum;
    barCode.Symbology = Fath.bcType.Code128;
    barCode.ShowText = true;
    e.Graphics.DrawImage(barCode.Image(240, 50), new Point(20, 5));
    
    float left = 2; 
    float top = 70;
    Font titlefont = new Font("仿宋", 10);
    Font font = new Font("仿宋", 8);
    e.Graphics.DrawString("天津百万奖彩票中心", titlefont, Brushes.Blue, left + 20, top, new StringFormat());
    
    Pen pen = new Pen(Color.Green, 1);
    e.Graphics.DrawLine(pen, new Point((int)left - 2, (int)top + 20), new Point((int)left + (int)180, (int)top + 20));
    
    for (int i = 0; i < numList.Count; i++)
    {
        e.Graphics.DrawString(numList[i], font, Brushes.Blue, left,
            top + titlefont.GetHeight(e.Graphics) + font.GetHeight(e.Graphics) * i + 12, new StringFormat());
    }
    
    float topPoint = titlefont.GetHeight(e.Graphics) + font.GetHeight(e.Graphics) * (numList.Count) + 22;
    e.Graphics.DrawLine(pen, new Point((int)left - 2, (int)top + (int)topPoint),
        new Point((int)left + (int)180, (int)top + (int)topPoint));
    
    string time = "购买时间:" + DateTime.Now.ToString("yyy-MM-dd  HH:mm:ss");
    e.Graphics.DrawString(time, font, Brushes.Blue, left, top + titlefont.GetHeight(e.Graphics)
        + font.GetHeight(e.Graphics) * (numList.Count + 1) + 12, new StringFormat());
    
    int qrcodetop = (int)(top + titlefont.GetHeight(e.Graphics) + font.GetHeight(e.Graphics) * (numList.Count + 3) + 12);
    int qrcodeleft = (int)left + 32;
    
    
    Image bmp = QRcodeCreator.GetQRCodeBmp("http://www.xiketang.com");
    
    e.Graphics.DrawImage(bmp, new Point(qrcodeleft, qrcodetop));
    e.Graphics.DrawString("扫描二维码可直接查询兑奖结果", font, Brushes.Blue, left, qrcodetop + bmp.Height + 10, new StringFormat());
}     
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
5 在Winform中使用打印功能
public partial class FrmMain : Form
{
    private PrintDocument printDoc = new PrintDocument();
    #region 初始化
    public FrmMain()
    {
        InitializeComponent();
        
        this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.LotteryPrintPage);
    }
    #endregion
    
    private void btnPrint_Click(object sender, EventArgs e)
    {
        this.printDoc.Print();
    }
    
    private void LotteryPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        string serialNum = DateTime.Now.ToString("yyyyMMddHHmmssms");
        this.objselector.PrintLottery(e, serialNum, objselector.GetPrintedNums());
    }
}
	
	
该文章在 2022/7/29 9:48:20 编辑过