版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/qq_41890694/article/details/87858923
之前由于个人项目需求需要打印订单,在winfrom方面我还没尝试过,后来通过查找资料,经过多番摸索调试后,还是觉得这种方法比较好,希望能帮到小伙伴。
实现截图::
实现代码::
#region 打印
private void btnstamp_Click(object sender, EventArgs e)
{
printDialog.Document = printDocument;
if (printDialog.ShowDialog() == DialogResult.OK)
{
printDocument.Print();
MessageBox.Show("打印成功!");
}
else
{
MessageBox.Show("打印失败!");
}
this.Close();
}
#endregion
#region 打印照片
private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//打印内容为局部的
//19 17
Bitmap _NewBitmap = new Bitmap
(pnlShenGouDingDan.Width + 13, pnlShenGouDingDan.Height + 13);
pnlShenGouDingDan.DrawToBitmap(_NewBitmap,
new Rectangle(13, 13, _NewBitmap.Width + 13, _NewBitmap.Height + 13));
e.Graphics.DrawImage(_NewBitmap, 13, 13, _NewBitmap.Width + 13, _NewBitmap.Height + 13);
}
#endregion