Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi all

I am working on a passbook printing project.

Here while printing what i have to do is when in a sheet 13 lines are printed then it should give 3 line feeds and start printing to the new sheet.

C#
if (k > 13)
               {
                       sr.WriteLine(Environment.NewLine);
                       sr.WriteLine(Environment.NewLine);
                       sr.WriteLine(Environment.NewLine);
               for (int n = 0; n <= k; n++)
                   {
                     sr.WriteLine(Environment.NewLine);
                   }
               }
               else
               {
                   for (int n = 0; n <= k; n++)
                   {
                       sr.WriteLine(Environment.NewLine);
                   }
               }

here k is a counter which i am maintaining for counting the number of rows printed.
but what i want is suppose if a person prints 20 lines at a time at that time this condition will not work.
So i have to check like when k==13 then it should give 3 line feeds then again starts printing normally..

Please tell me how to do this.

Please do ask if it's not clear.

Thank you
Posted

1 solution

Don't mix up printing and output to console. If you do output to console, there are no sheets. If you want to print to the printer (or other similar media, such as PDF/XPS), use the class System.Drawing.Printing.PrintDocument which gives you full control over print area (in the limits of the available page size/format):
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

By the way, your fragment of code has number of problems. One of them: sr.WriteLine(Environment.NewLine) makes little to know sense, this is the same as printing two empty lines, or simply calling sr.WriteLine() twice, because this is the same as calling sr.Write(Environment.NewLine).

—SA
 
Share this answer
 
v2

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