How Do I print a scrollable panel in VB.Net?

Hi ppl,

Have a scrollable panel in a form (panel height of about 850. Only panel is scrollable, not form). The panel is a form loaded with data which i need to print. Now we know that winforms dont have the .PrintForm function, so I tried that common code available which captures the form as a Bitmap, then sends that to the printer. Can get the panel to print, the problem is that it only prints what is visible on the screen, that is the rest of the panel which is reached via the scrollbars is not captured/printed......This is an urgent problem...any ideas?

Dont want to really deal with crystal reports instead as alot of the data is in listboxes and thus easier to print as viewed as on the screen.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try using the reflection object to create bitmap images of each individual control in the panel. Then combine these images with their respective coordinates into one big panel image then send it to the printer document component. The drawback is that it does not work on all controls.

Private Function GetControlBitmap(ByVal ctl As Control) As Bitmap
            Dim Methods() As System.Reflection.MethodInfo =
ctl.GetType.GetMethods( _
                System.Reflection.BindingFlags.Instance Or
            Dim i As Integer
            Dim OnPaintMethod As System.Reflection.MethodInfo
            For i = 0 To Methods.Length - 1
                If Methods(i).Name = "OnPaint" Then
                    OnPaintMethod = Methods(i)
                    Exit For
                End If

            If Not OnPaintMethod Is Nothing Then
                Dim bmp As New Bitmap(ctl.Width, ctl.Height)
                Dim g As Graphics = Graphics.FromImage(bmp)
                Dim PaintEventArgs As New
System.Windows.Forms.PaintEventArgs(g, New Rectangle(0, 0, ctl.Width,
                OnPaintMethod.Invoke(ctl, New Object() {PaintEventArgs})
                Return bmp
            End If
        End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.