Hello
I can print a panel (pnlPrint) using the following code. But, I'm not able to print a datagridview that already belongs to the same Form together on the second page so that the two leave in the same impression. I could make two different buttons to print the two separate panels, but I need the two panels to come out in the same print as the user can opt for the PDF printer and thus generate a two page file.
void Imprimir()
{
PrintDocument pd = new PrintDocument();
pd.DocumentName = "Relatório SisIndice";
pd.PrintPage += new PrintPageEventHandler(doc_PrintPage);
pd.DefaultPageSettings.Landscape = true;
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = pd;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
pd.Print();
}
}
private void doc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bmp = new Bitmap(pnlPrint.Width, pnlPrint.Height, pnlPrint.CreateGraphics());
pnlPrint.DrawToBitmap(bmp, new Rectangle(0, 0, pnlPrint.Width, pnlPrint.Height));
RectangleF bounds = e.PageSettings.PrintableArea;
float factor = ((float)bmp.Height / (float)bmp.Width);
e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, 1118, 855);
Bitmap bmp1 = new Bitmap(dgvDetGraf.Width, dgvDetGraf.Height, dgvDetGraf.CreateGraphics());
dgvDetGraf.DrawToBitmap(bmp1, new Rectangle(0, 0, dgvDetGraf.Width, dgvDetGraf.Height));
RectangleF bounds1 = e.PageSettings.PrintableArea;
e.Graphics.DrawImage(bmp1, bounds1.Left, bounds1.Top, 1118, 855);
e.HasMorePages = false;
}