ahmed sa

ahmed sa

  • NA
  • 289
  • 129.5k

print image in center of page proplem

Jun 15 2014 4:11 AM
This code print image
But it print in the top left of page
 how to print the image from picture box in center of page
size mode picturebox is zoom
the code by c# 2008 as following :

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap myBitmap1 = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(myBitmap1, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
e.Graphics.DrawImage(myBitmap1,0,0,0,0);
myBitmap1.Dispose();

}


private void print_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument myPrintDocument1 = new System.Drawing.Printing.PrintDocument();
PrintDialog myPrinDialog1 = new PrintDialog();
myPrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
myPrinDialog1.Document = myPrintDocument1;
printDocument1.OriginAtMargins = true;


if (myPrinDialog1.ShowDialog() == DialogResult.OK)
{
myPrintDocument1.Print();
}

}

What i modify in code to be able to print the image in center of page