In my application, I have a chart that is surrounded inside the panel. I added the printdocument component from the toolbar, and when I want to print the chart, I create a bitmap and I get the panel inside the bitmap (and, as a result, the chart that is inside the panel). My problem is that when I create a bitmap, when I send it to the printer to print it, it eats up part of the chart from the bottom and to the right. Below is my code for doing this
private void button1_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
printDialog.Document = printDocument1;
printDialog.UseEXDialog = true;
if (DialogResult.OK == printDialog.ShowDialog())
{
printDocument1.DocumentName = "Test Page Print";
printPreviewDialog1.Document = printDocument1;
if (DialogResult.OK == printPreviewDialog1.ShowDialog())
printDocument1.Print();
}
}
This is the button to initialize print_document. (I added a preview so I don't have to print it every time and waste paper and ink)
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(this.panel1.Width, this.panel1.Height);
this.panel1.DrawToBitmap(bm, new Rectangle(50, 50, this.panel1.Width + 50, this.panel1.Height + 50));
e.Graphics.DrawImage(bm, 0, 0);
}
, , , , , . , . ( , draw to bitmap
bm.Save(@"c:\LOAN_GRAPH.png");
, c:)
, , .