0

I want to print a Panel content but the result it's not high quality, I faced the same issue when I try to save a PictureBox image but I solve it with this Img.Setresolution(300, 300)

now I want to increase the quality of the result in any way ( also I tried to take a screenshot then store it in an image and print it I get a small image !! )

i tried this but it doesn't work for me :

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim tmpImg As New Bitmap(Panel1.Width, Panel1.Height)
    Using g As Graphics = Graphics.FromImage(tmpImg)
        g.CopyFromScreen(Panel1.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(Panel1.Width, Panel1.Height))
    End Using
    e.Graphics.DrawImage(tmpImg, 0, 0)
    Dim aPS As New PageSetupDialog
    aPS.Document = PrintDocument1


    'Dim bm As New Bitmap(Panel1.Width, Panel1.Height)
    'Panel1.DrawToBitmap(bm, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
    'e.Graphics.DrawImage(bm, 0, 0)
    'Dim aPS As New PageSetupDialog
    'aPS.Document = PrintDocument1
End Sub
Dr.andr
  • 7
  • 3
  • Can you specify what is the content of this Panel and how it got there? What happens when you set the size of the Image to print in `e.Graphics.DrawImage(tmpImg, ...)`? – Jimi Nov 13 '20 at 18:37
  • @Jimi this panel content : Labels, TextBox and image. when i print the content the quality its not good – Dr.andr Nov 13 '20 at 18:50
  • Try `Panel.DrawToBitmap()` or something like this: [How to use PrintDocument with a scrollable Panel?](https://stackoverflow.com/a/57257205/7444103). Look at the bottom, there's a link to the same procedure coded in VB.Net. Keep in mind that the DPI dscriptor of the Image you generate won't match the Printer's settings, so you have to match the DPI or scale the Image as required. – Jimi Nov 13 '20 at 19:01

0 Answers0