Posted on 2005-04-12
Last Modified: 2010-04-23
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)

Question by:SETP

    Author Comment

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


    Author Comment

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

    PrintPreviewDialog1.WindowState = FormWindowState.Maximized

    Author Comment

    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.

    LVL 1

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 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

    7 Experts available now in Live!

    Get 1:1 Help Now