场景
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, , );
}