其他分享
首页 > 其他分享> > Winform中使用printDocument控件打印pictureBox中的二维码照片

Winform中使用printDocument控件打印pictureBox中的二维码照片

作者:互联网

场景

Winform中使用zxing和Graphics实现自定义绘制二维码布局:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100127885

https://www.cnblogs.com/badaoliumangqizhi/p/11426919.html

在上面实现将二维码显示在pictureBox之中之后,将其打印。

效果

 

实现

页面拖拽一个printDocument控件。

 

 

拖拽之后的效果

然后再拖拽一个Button按钮,双击进入其点击事件中

 

private void button7_Click(object sender, EventArgs e)
        {
            PrintDialog MyPrintDg = new PrintDialog();
            MyPrintDg.Document = printDocument1;
            if (MyPrintDg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    printDocument1.Print();
                }
                catch
                {   //停止打印
                    printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs());
                }
            }
        }

 

找到页面设计器中拖拽的printDocument控件上,右击属性,找到事件列表,然后双击其PrintPage事件

编写如下代码:

 

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(pictureBox1.Image, 20, 20);
        }

 

运行效果

 

标签:控件,pictureBox,printDocument1,二维码,MyPrintDg,printDocument,拖拽
来源: https://www.cnblogs.com/badaoliumangqizhi/p/11427016.html