0
我試圖在MdiChild中打印pictureBox的內容。 調試代碼看起來像從不觸發PrintPage事件。 我主要在項目中使用此代碼:printing content of a picturebox在MdiChild中打印pictureBox
有什麼問題?
這裏是我的代碼:
private void stampaToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 activeChild = this.ActiveMdiChild as Form2;
PictureBox theBox = (PictureBox)activeChild.pictureBox1;
dastampare = theBox.Image as Bitmap;
printDocument1.OriginAtMargins = true;
printDocument1.DocumentName = "Prova";
printDialog1.Document = printDocument1;
printDialog1.ShowDialog();
if (printDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(dastampare, 0, 0);
}
注意:你調用'printDialog1.ShowDialog()'兩次。如果你的調試器到達'printDocument1.Print();'行而不是你的PrintPage事件,那麼你很可能沒有連接事件處理程序。 – LarsTech
你是完全正確的LarsTech。修正它刪除printDialog1.ShowDialog();我仍然無法觸發PrintPage事件。 :( – Podarce