在MdiChild中打印pictureBox

时间:2013-02-05 22:39:44

标签: c# printing picturebox mdichild

我正在尝试在MdiChild中打印pictureBox的内容。 调试代码看起来永远不会触发PrintPage事件。 我主要在项目中使用此代码:printing content of a 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);
    }

1 个答案:

答案 0 :(得分:0)

在表单的构造函数中,尝试连接事件处理程序:

public Form1() {
  InitializeComponent();
  printDocument1.PrintPage += printDocument1_PrintPage;
}