Click here to Skip to main content
15,936,122 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
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!!!
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.

Share this answer
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).
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.

Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900