Skip to content

Printing a pic

Francois van wyk

Asked Jul 7, 2007, 8:21 AM EDT2 answers
Share
LinkedInX
I am trying to program a button to print a pic(to the printer) from the pictureBox! I know i must use using System.Drawing.Printing; using System.IO; could somone plzz help

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Printing a image from a picturebox is actually quite simple. Try these steps and see if this will help you. • Drag a PrintDocument onto your Form from the ToolBox. Set the name to "pd1". (You will see its added to the component area below the form) • Drag a PrintPreviewDIALOG onto the form. Set the name to "ppd1". • Now select the PrintPreviewDialog and set the "Document" property to the printdocument. (located in the "Properties" window) • For me to fully illustrate the tools you can use, Drag two buttons onto the form. Set the properties of the first one as: Name: "btnPrint", Text: "Print". Set the properties of the second as: Name: "btnPreview", Text: "Preview". • Now double-click on btnPrint and btnPreview to generate event handlers. • Inside of btnPrint's event handler write the following code: pd1.Print(); • Inside of btnPreview's event handler write the following code: ppd1.ShowDialog(); *************************************** Now that we've wired up the controls, we now need to write the code that paints the picturebox image. • Switch back to Design View and Double-Click on "pd1" to generate an event handler. • Inside the pd1's event handler write the following code: (I am refering to the picturebox as "myPictureBox") //Code if (myPictureBox.Image != null) { int intPictPositionX = 50; int intPictPositionY = 50; int intPictWidth = myPictureBox.Width; int intPictHeight = myPictureBox.Height; e.Graphics.DrawImage(myPictureBox.Image, intPictPositionX, intPictPositionY, intPictWidth, intPictHeight); } Thats All! There are alot more options you can add, (number of copies, printer settings, etc). but this will get you started. Let me know if you need any more help! Richard
    0
  • 1 short reply