在WinForms中生成,自定义打印QR码

时间:2012-12-19 11:38:04

标签: winforms c#-4.0

我试图用一些字符串打印自定义QR码。

我面临的问题是无法将字符串放在正确的位置,而不能自定义输出。 Sample Image

我得到的是混乱。我可以创建模板和打印吗?

自定义代码

 CurrentY = 0;
                CurrentX = 0;
                InvSubTitleHeight = (int)(InvSubTitleFont.GetHeight(g));
                // Get Titles Length:
                int lenInvSubTitle1 = (int)g.MeasureString("Bill ID : " + billId, InvSubTitleFont).Width;
                int lenInvSubTitle2 = (int)g.MeasureString("Bill Amount : " + billAmt, InvSubTitleFont).Width;
                int lenInvSubTitle3 = (int)g.MeasureString("Date : " + DateTime.Now.ToString("dd/MM/yyyy"), InvSubTitleFont).Width;

                // Set Titles Left:
                int xInvSubTitle1 = CurrentX + lenInvSubTitle1 / 2;
                int xInvSubTitle2 = CurrentX + lenInvSubTitle2 / 2;
                int xInvSubTitle3 = CurrentX + lenInvSubTitle3 / 2;

                // Draw Invoice Head:
                if (billId != "")
                {
                    CurrentY = CurrentY + InvSubTitleHeight;
                    g.DrawString("Bill ID : " + billId, InvSubTitleFont, BlackBrush, 0, CurrentY);
                }
                if (billAmt != "")
                {
                    CurrentY = CurrentY + InvSubTitleHeight + 5;
                    g.DrawString("Bill Amount : " + billAmt, InvSubTitleFont, BlackBrush, 0, CurrentY);
                }

                CurrentY = CurrentY + InvSubTitleHeight + 5;

                g.DrawString("Date : " + DateTime.Now.ToString("dd/MM/yyyy"), InvSubTitleFont, BlackBrush, 0, CurrentY);

                CurrentY = CurrentY + InvSubTitleHeight + 15;

                var image = QRValidation.CreateImage(img);
                var p = new Point(0, CurrentY);
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.DrawImage(image, p);
                CurrentY += image.Height + 20;

                //Add bottom Text

                g.DrawString("Scan the image above with your", InvSubTitleFont, BlackBrush, 0, CurrentY);
                CurrentY = CurrentY + InvSubTitleHeight + 2;
                g.DrawString("X app and earn reward", InvSubTitleFont, BlackBrush, 0, CurrentY);
                CurrentY = CurrentY + InvSubTitleHeight + 2;
                g.DrawString("points for your last purchase", InvSubTitleFont, BlackBrush, 0, CurrentY);
                CurrentY = CurrentY + InvSubTitleHeight + 25;
                g.DrawString("You can scan this QR Code only", new Font("Times New Roman", 10, FontStyle.Bold), BlackBrush, 0, CurrentY);
                CurrentY = CurrentY + InvSubTitleHeight + 3;
                g.DrawString("once.", new Font("Times New Roman", 10, FontStyle.Bold), BlackBrush, 90, CurrentY);
                // Draw line:
                CurrentY = CurrentY + InvSubTitleHeight + 25;
                var width = (int) g.MeasureString("Powered by X", InvSubTitleFont).Width;
                g.DrawLine(new Pen(Brushes.DarkCyan, 3), CurrentX, CurrentY, width+2, CurrentY);

                CurrentY = CurrentY + InvSubTitleHeight + 5;
                g.DrawString("Powered by X", InvSubTitleFont, BlackBrush, 0, CurrentY);

0 个答案:

没有答案