I created a barcode and displayed it in a picture box and i want to print it.
i can't figure how to do it..

Recommended Answers

All 4 Replies

PictureBox1.Image.Save("C:\img.jpg")
If My.Computer.FileSystem.FileExists("C:\img.jpg") Then
   Print("C:\img.jpg")
End If

This is untested but it should work.

Print("C:\img.jpg")

This does not print to a printer.

Try this instead

Dim WithEvents printDoc As New Printing.PrintDocument()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        printDoc.Print()
    End Sub

    Private Sub PrintImage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDoc.PrintPage
        e.Graphics.DrawImage(PictureBox1.Image, e.MarginBounds.Left, e.MarginBounds.Top)
    End Sub

Note: This prints to the default printer and the image is printed in the top left corner at its native size

Oh sorry, guess that is what I get for not testing haha. Thanks for the code. Now I know ;)

figured it out yesterday..

just want to share this code

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As   System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim newMargins As System.Drawing.Printing.Margins
        newMargins = New System.Drawing.Printing.Margins(0.2, 0.2, 0.2, 0.2)
        PrintDocument1.DefaultPageSettings.Margins = newMargins
        e.Graphics.DrawImage(barcode, 0, 0)
    End Sub

the I used

PrintDocument1.Print()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.