Chris Bacon Chris Bacon -4 years ago 90
C# Question

Print & Print Preview a Bitmap in c#

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,


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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download