1

I have a sticker I want to print from my form but I cant seem to figure out how to print the text overlaying on the picture box, and I can only print the picture itself. So basically what I wanted was the area of the picture box and the labels on top of the picturebox to be shown in the printout.

I have this so far, not sure how to also represent all labels within the picturebox area.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 
    PrintDialog1.Document = PrintDocument1

    PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings

    PrintDialog1.AllowSomePages = True

    If PrintDialog1.ShowDialog = DialogResult.OK Then
        PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings


        PrintDocument1.Print()
    End If
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim newMargins = New 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(PictureBox1.Image, 0, 0)
End Sub
lerne8423
  • 31
  • 6
  • 1
    Are you talking about actual `Label` controls? If not, what are you talking about? If so, are those `Labels` parented by the form or the `PictureBox`? – jmcilhinney Dec 07 '20 at 06:14
  • You have two main choices. You can call `DrawToBitmap` on a control to create a single `Bitmap` and then draw that when you print. In that case, either the `Labels` would have to be children of the `PictureBox` or you'd have to make all of them children of a `Panel`. In the latter case, you'd need the `PictureBox` in front because `DrawToBitmap` reverses the z-order. Alternatively, you can call `DrawImage` and then call `DrawString` once for each bit of text you want to print, which might be the `Text` of each `Label`. – jmcilhinney Dec 07 '20 at 06:21
  • You can use this: [How to print hidden and visible content of a Container with ScrollBars](https://stackoverflow.com/a/57309095/7444103). Add your Controls to a Panel container and parent the Labels to the PictureBox (you'll have to relocate the Labels at run-time if you're not already doing it) – Jimi Dec 07 '20 at 13:56

0 Answers0