I have a standard WinForm written in VB.NET 2003. I'd like to place a button on it that when the user clicks on it, it prints the form. How can I do this? I basically want a snapshot of the form on paper, but it must be done programatically. Even better would be if I could choose what part of the form I want to print (I only need the lower 3/4 of the form printed)

Who is Participating?
GhostModConnect With a Mentor Commented:
PAQed with points refunded (500)

Community Support Moderator
SETPAuthor Commented:
OK, figured out how to print. Actually, I wanted to print a panel on the form, not the entire form. This is the code I used:

        Dim mygraphics As Graphics = oPanel.CreateGraphics
        Dim s As Size = oPanel.Size
        memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
        Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
        Dim dc1 As IntPtr = mygraphics.GetHdc
        Dim dc2 As IntPtr = memoryGraphics.GetHdc
        BitBlt(dc2, 0, 0, oPanel.Width, oPanel.Height, dc1, 0, 0, 13369376)
        PrintPreviewDialog1.Document = PrintDocument1

It brings up a PrintPreview first. Only problem is that the PrintPreview appears as a small little window on the top-left corner of the screen and the Zoom is set to Auto. How can I do it so that the PrintPreview window appears maximized and the zoom is set to 100%?

SETPAuthor Commented:
OK, figured out the Maximized part. It's simply

PrintPreviewDialog1.WindowState = FormWindowState.Maximized
SETPAuthor Commented:
In the example above, when the PrintPreviewDialog is shown, and I click on its Print button, it just prints, without going to the Windows Print screen where I can select a printer, paper orientation, copies, etc. How can I do that? It doesn't necessarily have to be then. I can have a separate place for "Page Setup" where it gets done there.

All Courses

From novice to tech pro — start learning today.