我有一个PictureBox 列表。以下代码适用于单个 PictureBox。无论纸张大小如何,如何在新页面中打印每个 PictureBox(或 Image) ?谢谢 !
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += Doc_PrintPage;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
if (dlgSettings.ShowDialog() == DialogResult.OK)
{
doc.Print();
}
}
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
Bitmap bmp = new Bitmap(picBox1.Width, picBox1.Height);
//THIS IS OKAY FOR A SINGLE PICTURE BOX.
picBox1.DrawToBitmap(bmp,
new Rectangle(0, 0, picBox1.Width,
picBox1.Height));
e.Graphics.DrawImage((Image)bmp, x, y);
}