Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing in VB.Net

8 views
Skip to first unread message

Jerry Spence1

unread,
Aug 22, 2006, 8:27:51 PM8/22/06
to
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


Jan Hyde

unread,
Aug 23, 2006, 9:48:01 AM8/23/06
to
"Jerry Spence1" <jerry....@somewhere.com>'s wild thoughts
were released on Wed, 23 Aug 2006 01:27:51 +0100 bearing the
following fruit:


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)

--
They considered their silver anniversary a sterling event. (Jumble)

ShaneO

unread,
Aug 23, 2006, 5:49:29 PM8/23/06
to
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.

0 new messages