Solved Print windows form with scroll bar

Posted on 2009-04-27
Last Modified: 2013-11-26

I have laid out labels on a form to simulate a report.  I want to be able to print the form so that I do not have to re create the report using a report designer.   I have found code that will allow me to print what is viewable however this report is somewhat long and requires a scroll bar.  

How do I print the form so that all the information is printed?   I would prefer code using VS 2005.  However I can translate C# or switch to VS 2008.

Thanks in advance!
Question by:SZachmann
    LVL 1

    Expert Comment


    The javascript function Window.print() should work for what you're asking.

    I imagine you have a button to print the page, this button should call the print function:

    <asp:Button id="btnPrint" runat="server" text="Print" onclick="window.print()" />

    "onclick" can also be replaced by "OnClientClick" (which is also available on VS2005 if I remember correctly).

    I hope this works for you.
    LVL 1

    Expert Comment

    I'm sorry, I thought I was in the ASP.Net section.
    My solution won't work for Windows Forms of course.

    LVL 2

    Author Comment

    TharkunX thanks for posting but yes this is a windows form.  
    LVL 83

    Expert Comment

    You can set the
    and then resize the form to show all the contents. I am not sure about the class you are using but if this class takes into account the full form rather than the screen size, you can resize the form beyond the screen limits, print it, and then restore it to previous size.
    LVL 2

    Author Comment


    I was able to figure it out and I did not need to utilize you mentioned.  However thank you for the reply.  I will post the code I used to print the form a bit later.

    Thanks EE
    LVL 2

    Accepted Solution

    Here is the code I used to print the form.  I put everything I wanted to print into a group box called 'gbprintReport' this was because my form had a tab control with a scroll bar so the form size was not the correct height and width.
        Dim WithEvents PD As New Printing.PrintDocument
        Dim PPD As New PrintPreviewDialog
      Private Sub btnPrintForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintForm.Click
            PPD.Document = PD
        End Sub
        Private Sub PD_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PD.PrintPage
            Dim Bmp As New Bitmap(gbprintReport.Width, gbprintReport.Height)
            gbprintReport.BackColor = Color.White
            gbprintReport.DrawToBitmap(Bmp, New Rectangle(0, 0, Bmp.Width, Bmp.Height))
            e.Graphics.DrawImage(Bmp, 0, 0)
            gbprintReport.BackColor = Color.Transparent
        End Sub

    Open in new window


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now