Hi @AMER SAID ,
I store some pictures in a folder and make a test on my side.
Here's the code you can refer to.
Private picCount As Integer = ...' count of pcitures
Private picIndex As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim printDialog1 As PrintDialog = New PrintDialog()
printDialog1.Document = PrintDocument1
Dim result As DialogResult = printDialog1.ShowDialog()
If result = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim nameFont As Font = New Font("Arial", 20)
Dim recWidth As Integer = e.PageSettings.PrintableArea.Width / 3
Dim recHeight As Integer = e.PageSettings.PrintableArea.Height / 3
Dim x As Single = e.PageSettings.PrintableArea.Left
Dim y As Single = e.PageSettings.PrintableArea.Top
Dim stringFormat As New StringFormat()
stringFormat.Alignment = StringAlignment.Center
stringFormat.LineAlignment = StringAlignment.Center
While picIndex <= picCount
Dim rectText As New Rectangle(x, y, recWidth - 50, 30)
Dim image As Image = image.FromFile("my picture path\image" & picIndex & ".jpg")
If x < e.PageSettings.PrintableArea.Width And y < e.PageSettings.PrintableArea.Height Then
e.Graphics.DrawString("name" & picIndex, nameFont, New SolidBrush(Color.Black), rectText, stringFormat)
e.Graphics.DrawImage(image, New Rectangle(x, y + 40, recWidth - 50, recHeight - 150))
x += recWidth
ElseIf x > e.PageSettings.PrintableArea.Width Then
x = e.PageSettings.PrintableArea.Left
y += recHeight
If y < e.PageSettings.PrintableArea.Height Then
rectText = New Rectangle(x, y, recWidth - 50, 30)
e.Graphics.DrawString("name" & picIndex, nameFont, New SolidBrush(Color.Black), rectText, stringFormat)
e.Graphics.DrawImage(image, New Rectangle(x, y + 40, recWidth - 50, recHeight - 150))
x += recWidth
Else
e.HasMorePages = True
Return
End If
End If
picIndex += 1
End While
End Sub
Result of my 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.