Print & Print Preview a Bitmap in c#

Chris Bacon picture Chris Bacon · Nov 22, 2010 · Viewed 14.1k times · Source

I have made a program that draws on a image on a picturebox and now i want to print and print preview this, but don't know how. Please Help,

Thanks

EDIT I have tried using print and print preview dialogs but don't know how to work them properly to print and show the contents of a picturebox and its image

Answer

Hans Passant picture Hans Passant · Nov 22, 2010

Drop a PrintDocument on your form. You'll want a PrintPreviewDialog and PrintDialog as well. Set the dialogs' Document property to the PrintDocument. Implement the PrintPage event handler for it, could be a simple as:

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
        e.Graphics.DrawImage(pictureBox1.Image, 0, 0);
    }

And add buttons or menu items to call the dialogs' ShowDialog() method.