Thursday, 29 July 2021

Print from Picturebox VB.NET

Visual Studio 2019

 

 

 To print an Image from a picturebox try the following method( used for printing QR Codes in this instance)

 

Once the picturebox has been loaded and if required saved ad the ref to a  print document  highlighted


 Private Sub qrcodeGen(msg As String)


        Dim qrCode As New QRCodeEncoder
        qrCode.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE
        qrCode.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L
        Me.PictureBox1.Image = qrCode.Encode(msg, System.Text.Encoding.UTF8)
        PictureBox1.Image.Save("The path to save")

        PrintDocument1.Print()


    End Sub

 

then add the following 

Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage


        e.Graphics.DrawImage(PictureBox1.Image, 0, 0)


    End Sub


The image in the picturebox should now print.

 

 

No comments:

Post a Comment

Samsung Android Keyboard

  If you have a Samsung phone or pad and the keyboard is set to Google give the Samsung one a try. Just go into the keyboard settings and ...