Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5C#
Hello
 
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;
                    printForm1.Print();
                }
 
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
Ritwesh1.7K
Comments
Sergey Alexandrovich Kryukov at 21-Sep-12 14:26pm
   
No it is not urgent, believe me :-). And "I am encountering a problem" is absolutely non-descriptive. --SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Ritwesh at 28-Sep-12 15:14pm
   
Hello, 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 at 29-Sep-12 0:57am
   
it may be a printer problem..because same code i used worked for me
Ritwesh at 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 at 1-Oct-12 13:43pm
   
always welcome:)..glad to see you found solution
Ritwesh at 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 at 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
good
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? Smile | :)
 
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:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].
 
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:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].
 
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 (http://en.wikipedia.org/wiki/Framework_Class_Library[^]), as you want better compatibility and problem-free maintenance.
 
—SA
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 339
1 Sergey Alexandrovich Kryukov 285
2 OriginalGriff 280
3 Peter Leow 171
4 Abhinav S 168
0 Sergey Alexandrovich Kryukov 8,979
1 OriginalGriff 5,280
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid