Print & Print Preview a Bitmap in c#

2019-08-18 02:11发布

问题:

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

回答1:

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.