Link to home
Start Free TrialLog in
Avatar of SETP
SETP

asked on

Printing

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)

Thanks
Avatar of SETP
SETP

ASKER

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)
        mygraphics.ReleaseHdc(dc1)
        memoryGraphics.ReleaseHdc(dc2)
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.Show()

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%?

Thanks
Avatar of SETP

ASKER

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

PrintPreviewDialog1.WindowState = FormWindowState.Maximized
Avatar of SETP

ASKER

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.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial