Hi @Kairo Martins ,
Leave preview controls(DataGridView or ListView), you can print images directly.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ImageList1.ImageSize = New Size(PictureBox1.Width, PictureBox1.Height)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
ImageList1.Images.Add(PictureBox1.BackgroundImage)
Label1.Text = ImageList1.Images.Count
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim picCount As Integer = ImageList1.Images.Count
If picCount > 0 Then
Dim rect As Rectangle = e.MarginBounds
Dim width As Single = 1.0F * rect.Width / 3
Dim height As Single = width
Dim columns = 3
Dim ypos = 0
Dim index As Integer = 0
While ypos + height < 1.0F * rect.Height
For c As Integer = 0 To columns - 1
Dim pRect As RectangleF = New RectangleF(c * width, ypos, width, height)
e.Graphics.DrawImage(ImageList1.Images(index), pRect)
index += 1
If index > ImageList1.Images.Count - 1 Then
Return
End If
Next
ypos = ypos + height
End While
e.HasMorePages = True
Else
MessageBox.Show("You must generate qr code first")
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim qrGenerator As QRCodeGenerator = New QRCodeGenerator()
Dim qrCodeData As QRCodeData = qrGenerator.CreateQrCode("Hello world", QRCodeGenerator.ECCLevel.Q)
Dim qrCode As QRCode = New QRCode(qrCodeData)
Dim qrCodeImage As Bitmap = qrCode.GetGraphic(20)
PictureBox1.BackgroundImage = qrCodeImage
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim printDialog As PrintDialog = New PrintDialog()
printDialog.Document = PrintDocument1
If printDialog.ShowDialog() = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Result of the test.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.