Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2611
  • Last Modified:

Vb.net Print windows form with scroll bar


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 VB.net code using VS 2005.  However I can translate C# or switch to VS 2008.

Thanks in advance!
  • 3
  • 2
1 Solution

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.
I'm sorry, I thought I was in the ASP.Net section.
My solution won't work for Windows Forms of course.

SZachmannAuthor Commented:
TharkunX thanks for posting but yes this is a windows form.  
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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.
SZachmannAuthor Commented:

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
SZachmannAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now