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.