Click here to Skip to main content
13,090,930 members (46,699 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am coding using Visual Studio 2008. I am trying to print a form using PrintForm from Visual Basic Power Packs. I have used the following code:
using (PrintDialog pd = new PrintDialog())
                    printForm1.Form = this;
                    if (pd.ShowDialog() == DialogResult.OK)
                        printForm1.PrinterSettings = pd.PrinterSettings;

But I am encountering a problem. When I am printing a distorted print out is coming out exactly as shown in the print preview but my for seems absolutely okay. Please help me out. Its urgent!!!
Posted 21-Sep-12 8:05am
Sergey Alexandrovich Kryukov 21-Sep-12 14:26pm
No it is not urgent, believe me :-).
And "I am encountering a problem" is absolutely non-descriptive.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Ritwesh 28-Sep-12 15:14pm
I tried out the code in your first link. I used a PrintDialog control along with the code to get the printer settings from user. When the document is viewed in print preview it is looking good, but when I am printing it a blank page comes out. Can you give me any solution to it??Plz.
ridoy 29-Sep-12 0:57am
it may be a printer problem..because same code i used worked for me
Ritwesh 1-Oct-12 13:36pm
Thanks for your suggestions but figured out my mistake. My mistake was that I was printing from the PrintDialog when my image to be printed was assigned to my PrintDocument. Sorry for the botheration and thanks again for your help.
ridoy 1-Oct-12 13:43pm
always welcome:)..glad to see you found solution
Ritwesh 3-Nov-12 14:56pm
Shuvo bijoya dada. Ami programming-e novice ebong kono teacher chchara nije nije sekhar chesta kori. All your solutions have been of great help to me. Tai ami tomake request korchi je tumi please amake aro bhalo programming shikhte help koro. Tomar shathe amar jogajog korbar khub ichche. Ki kore contact korbo janao? Please help me out with my programming(a request).
ridoy 3-Nov-12 15:51pm
Shuvo Bijoya to you also.Glad to see you're interested in programming and want my guide.Give me your email address,when i got it i will send mail to you and then you can communicate with me.But as this is a question/answer section,so i will remove your message(email id)after i will get it.Happy Coding..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Printing a form is not a good idea. Usually, a form contains some pure computer style controls: combo boxes, check boxes — you name it. When a user prints it all on paper, what can she or he click on? :-)

More reasonable approach is to separate UI and other parts of your application and have some data layer, or some data model which should be fundamental relative to the UI. It should have different (by perhaps similar) presentations for the form-based UI, maybe some other UI, printed version and maybe more. The usual way of printing, especially in the System.Windows.Forms applications is using the class System.Drawing.Printing.PrintDocument. Please see:[^].

You can use the basic code sample provided at the end of this article. Pay attention that the rendering is based on the instance of the class System.Drawing.Graphics:[^].

This will allow you to use the same code for some other rendering, for example, for saving identical graphics into a bitmap. You should have a method having a Graphics parameter, to be used in both cases, or more.

I also would advise you to avoid VB.NET-specific libraries and use only .NET FCL ([^]), as you want better compatibility and problem-free maintenance.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100