C#QR코드 생성 및 인쇄

7894 단어 C#
//         
    public static void GetPrintPicture(Bitmap image, AssetEntity asset, PrintPageEventArgs g)
        {
            int height = 5;
            Font font = new Font("  ", 10f);
            Brush brush = new SolidBrush(Color.Black);
            g.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            int interval = 15;
            int pointX = 5;
            Rectangle destRect = new Rectangle(190, 10, image.Width, image.Height);
            g.Graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
            height += 8;
            RectangleF layoutRectangle = new RectangleF(pointX, height, 260f, 85f);
            g.Graphics.DrawString("    :" + asset.Serial, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.Name, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("      :" + asset.Category, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.Model, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.Manufacturer, font, brush, layoutRectangle);


            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.StartUseTime, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.Price, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.Department, font, brush, layoutRectangle);

            //height += interval;
            layoutRectangle = new RectangleF(pointX + 150, height, 230f, 85f);
            g.Graphics.DrawString("   :" + asset.Manager, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
            g.Graphics.DrawString("    :" + asset.StoragePlace, font, brush, layoutRectangle);

            height += interval;
            layoutRectangle = new RectangleF(pointX, height, 240f, 85f);
            g.Graphics.DrawString("      :" + asset.Remark, font, brush, layoutRectangle);

        }
//    
    private void sbtnPrintQRCode_Click(object sender, EventArgs e)
        {
            PrintDocument document = new PrintDocument();
            Margins margins = new Margins(0x87, 20, 5, 20);
            document.DefaultPageSettings.Margins = margins;
            PrintPreviewDialog dialog = new PrintPreviewDialog();
            document.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            dialog.Document = document;
            try
            {
                if (this.CurrentPrintQRCode != null && this.CurrentPrintQRCode.Count() > 0)
                {
                   document.Print();
                   Thread.Sleep(1000);
                }
            }
            catch (Exception exception)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(exception.Message, "    ", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                document.PrintController.OnEndPrint(document, new PrintEventArgs());
            }
        }
private void pd_PrintPage(object sender, PrintPageEventArgs e) //      
    {
        //PointF f = new PointF(20, 10);//    
        //if (currentPrintImage != null)
        //{
        //    e.Graphics.DrawImage(this.currentPrintImage, f);
        //}
        CreatePicture.GetPrintPicture(this.bitmap, this.assetInfo, e);
       // Font font = new Font("  ", 12);
        //Brush bru = Brushes.Blue; 
        //for (int i = 1; i <= 5; i++)
        //{
         //   e.Graphics.DrawString("Hello world ", font, bru, i*20, i*20);
        //}
    }

좋은 웹페이지 즐겨찾기