Winform中使用printDocument控件打印pictureBox中的二维码照片
生活随笔
收集整理的這篇文章主要介紹了
Winform中使用printDocument控件打印pictureBox中的二维码照片
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
場景
Winform中使用zxing和Graphics實現(xiàn)自定義繪制二維碼布局:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100127885
https://www.cnblogs.com/badaoliumangqizhi/p/11426919.html
在上面實現(xiàn)將二維碼顯示在pictureBox之中之后,將其打印。
效果
?
實現(xiàn)
頁面拖拽一個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());}}}找到頁面設(shè)計器中拖拽的printDocument控件上,右擊屬性,找到事件列表,然后雙擊其PrintPage事件
?
編寫如下代碼:
?private void printDocument1_PrintPage(object sender, PrintPageEventArgs e){e.Graphics.DrawImage(pictureBox1.Image, 20, 20);}運行效果
?
總結(jié)
以上是生活随笔為你收集整理的Winform中使用printDocument控件打印pictureBox中的二维码照片的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Winform中使用zxing和Grap
- 下一篇: Winform中使用ZedGraph实现