I have looked on the web for a solution to print scrollable panel larger than can be fitted on the screen but couldn't find any solution and it looks like that many people has this problem!
PrintForm (printform powerpack component) can not do this because it only capture that part of the panel that is fitted on the screen.
And if you want to do this with the PrintDocument component and print all the visible parts of the form grids,tablelayoutpanels etc and to formate it correctly then you can become really frustrated!

Here is my solution to print scrollable panels larger than can be fitted on the screen..

    Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As Integer) As Integer

    Private Enum EDrawingOptions As Integer
        PRF_CHECKVISIBLE = &H1
        PRF_NONCLIENT = &H2
        PRF_CLIENT = &H4
        PRF_ERASEBKGND = &H8
        PRF_CHILDREN = &H10
        PRF_OWNED = &H20
    End Enum

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

        Const WM_PRINT As Integer = &H317
        Dim myBmp As Bitmap
        Dim myGraphics As Graphics
        Dim hdc As System.IntPtr

        Dim g As Graphics
        g = e.Graphics
        myBmp = New Bitmap(Panel1.DisplayRectangle.Width, Panel1.DisplayRectangle.Height)
        myGraphics = Graphics.FromImage(myBmp)
        hdc = myGraphics.GetHdc

        Call SendMessage(Panel1.Handle, WM_PRINT, hdc, EDrawingOptions.PRF_CHILDREN Or EDrawingOptions.PRF_CLIENT Or EDrawingOptions.PRF_NONCLIENT Or EDrawingOptions.PRF_OWNED)

        myGraphics.ReleaseHdc(hdc)
        g.DrawImage(myBmp, 0, 0)
        g.Dispose()
        e.HasMorePages = False
        myGraphics.Dispose()
        myGraphics = Nothing
        myBmp = Nothing

    End Sub

    Private Sub SkrivUt1ExToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SkrivUt1ExToolStripMenuItem.Click

        PrintDocument1.Print()

    End Sub

What's the reason you post this here?

Hi Dragomir 1, welcome here at Daniweb.
You will never print a Panel. You will want to print what is drawn on the Panel,I guess.
I'm affraid you have to do some calculations example here and work with the HasMorePages property.

Thank you very much

That's work very well for me
Yeah !
I Replaced "Panel1". for "Me."

There is a much more easier way of doing this
This will create a page containing all the contents of the scrollable panel

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

        ' Make the Panel to AutoSize
        ' This makes the panel to expand revealing the hidden scrollable content
        ' The expansion happens internally
        Panel1.AutoSize = True

        ' Make a bitmap image of the revealed panel size
        Dim b As New Bitmap(Panel1.DisplayRectangle.Width, Panel1.DisplayRectangle.Height)
        Panel1.DrawToBitmap(b, Panel1.ClientRectangle)

        e.Graphics.DrawImage(b, New Point(40, 40))

        ' Remove the AutoSize property
        ' This makes the panel to contract to its original size
        Panel1.AutoSize = False
 End Sub

hmm its not working for me oo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.