1,105,332 Community Members

Print scrollable panel (with height larger than can be fitted on the screen

Member Avatar
Dragomir_1
Newbie Poster
1 post since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
Member Avatar
Claundray
Newbie Poster
1 post since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

What's the reason you post this here?

Member Avatar
ddanbe
Posting Expert
5,336 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 904 [?]
Skill Endorsements: 46 [?]
Featured
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: