Printing in VB.Net

J

Jerry Spence1

The following seemed so simple in VB6 (CD1 is CommonDialogue1)

CD1.CancelError = True
CD1.ShowPrinter
Printer.PaintPicture ActiveForm.Picture1.Picture, 720, 720

to print the image in a picturebox.

I have spent hours Googling to try and fathom out how to do it in VB.Net
(2005). Surely it doesn't take all the code I've seen?

-Jerry
 
J

Jan Hyde

"Jerry Spence1" <[email protected]>'s wild thoughts
were released on Wed, 23 Aug 2006 01:27:51 +0100 bearing the
following fruit:
The following seemed so simple in VB6 (CD1 is CommonDialogue1)

CD1.CancelError = True
CD1.ShowPrinter
Printer.PaintPicture ActiveForm.Picture1.Picture, 720, 720

to print the image in a picturebox.

I have spent hours Googling to try and fathom out how to do it in VB.Net
(2005). Surely it doesn't take all the code I've seen?

-Jerry


Well the VB6 code you quote isn't as straight forward as it
seems. In your example the first two lines have no effect on
the third, and more code is required to determine which
printer the user selected.






Jan Hyde (VB MVP)
 
S

ShaneO

Jerry said:
The following seemed so simple in VB6 (CD1 is CommonDialogue1)

CD1.CancelError = True
CD1.ShowPrinter
Printer.PaintPicture ActiveForm.Picture1.Picture, 720, 720

to print the image in a picturebox.

I have spent hours Googling to try and fathom out how to do it in VB.Net
(2005). Surely it doesn't take all the code I've seen?

-Jerry
Hello Jerry,

Don't worry - it still is, but like you I have found that just about
every explanation I read for doing things in VB.Net seems so complicated
- most times it just isn't! (I'd hate to see some of the code that
people are producing!!!)

The simplest way I could provide the functionality in VB.Net (2005) as
in your example is -

1. Place a PrintDialog Control onto your Form.
2. Place a PrintDocument Control onto your Form.
3. Place a Button Control onto your Form.
4. Place a PictureBox Control onto your Form.
5. In the Button Click Event write -

If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = System.Drawing.Image.FromFile("C:\Image.jpg")
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
End If

5. In the PrintDocument1 PrintPage Event write -

e.Graphics.DrawImage(PictureBox1.Image, New Point(100, 100))

That's it!! While this is not very elegant, it does provide the ability
to print whatever image is contained in the PictureBox in the same
manner that your code would provide.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top