Pergunta

I'm trying to print the content of a pictureBox in a MdiChild. Debugging the code looks like it never triggers the PrintPage event. I've mainly used this code for the project: printing content of a picturebox

What is wrong ?

Here is my code:

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);
    }
Foi útil?

Solução

In your form's constructor, try wiring up the eventhandler:

public Form1() {
  InitializeComponent();
  printDocument1.PrintPage += printDocument1_PrintPage;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top