Print Picture
-
I have a picture on picture box and I want to press a button to print it but it not work how can i correct this:
private void button1_Click(object sender, System.EventArgs e) { try { PrintDocument pd = new PrintDocument(); pd.Print(); } catch (Exception ex) { MessageBox.Show("An error occurred while printing", ex.ToString()); } } private void pd_PrintPage(object sender, PrintPageEventArgs ev) { string path = @"D:\PatientImages\10.jgp"; ev.Graphics.DrawImage(Image.FromFile(path), ev.Graphics.VisibleClipBounds); ev.HasMorePages = true; }
and i want to print direct to printer so how can i do it? Thanks in advanced Rock Throught The Night -
I have a picture on picture box and I want to press a button to print it but it not work how can i correct this:
private void button1_Click(object sender, System.EventArgs e) { try { PrintDocument pd = new PrintDocument(); pd.Print(); } catch (Exception ex) { MessageBox.Show("An error occurred while printing", ex.ToString()); } } private void pd_PrintPage(object sender, PrintPageEventArgs ev) { string path = @"D:\PatientImages\10.jgp"; ev.Graphics.DrawImage(Image.FromFile(path), ev.Graphics.VisibleClipBounds); ev.HasMorePages = true; }
and i want to print direct to printer so how can i do it? Thanks in advanced Rock Throught The NightFirst of all, you don't need to reload the
Image
if it's already in yourPictureBox
. Just useev.Graphics.DrawImage(_pictureBox1_.Image, ...)
. Second, are you getting any errors? Is yourMessageBox
in your exception handler showing up? Please be specific since your code should be right (except that if you're scaling the image to the page, I'm not sure why you're settingev.HasMorePages
totrue
).Microsoft MVP, Visual C# My Articles
-
First of all, you don't need to reload the
Image
if it's already in yourPictureBox
. Just useev.Graphics.DrawImage(_pictureBox1_.Image, ...)
. Second, are you getting any errors? Is yourMessageBox
in your exception handler showing up? Please be specific since your code should be right (except that if you're scaling the image to the page, I'm not sure why you're settingev.HasMorePages
totrue
).Microsoft MVP, Visual C# My Articles
please show me how to pint the image by using the printer when i pess the print button thanks Rock Throught The Night
-
please show me how to pint the image by using the printer when i pess the print button thanks Rock Throught The Night
Um, call
PrintDocument.Print
like you already did. If you want to know how to select a different printer, then you need to read the documentation in the .NET Framework SDK, like for thePrintDocument.PrinterSettings
property, which has a printer calledPrinterName
. You can also use thePrinterSettings.InstalledPrinters
static property to get a collection of printers that are installed. All of these properties and methods I've mentioned have plenty of sample source code that's not worth duplicating here.Microsoft MVP, Visual C# My Articles