Hi,
I have the following code that prints me the text that I defined.
(That's a pice of code that I have modified.)
In this moment when I run the code it prints only one page, cutting the rest.
How can I know if there are another pages to print and print them?
ThanksCode:using System; using System.Collections.Generic; using System.Windows.Forms; //pt printare using System.ComponentModel; using System.Drawing; using System.Drawing.Printing; using System.IO; namespace WindowsApplication1 { public class PrintingExample : System.Windows.Forms.Form { private Font printFont; private string text_de_tiparit; public PrintingExample(string text) : base() { // The Windows Forms Designer requires the following call. //InitializeComponent(); text_de_tiparit = text; printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler (this.pd_PrintPage); pd.Print(); } // The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; string line = null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); // Print each line of the file. //while (count < linesPerPage && //((line = streamToPrint.ReadLine()) != null)) //{ line = text_de_tiparit; yPos = topMargin; // + (count * //printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); //count++; //} // If more lines exist, print another page. //if (line != null) //ev.HasMorePages = true; //else //ev.HasMorePages = false; } // This is the main entry point for the application. public static void Main(string[] args) { string text_de_tiparit = "a\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\n"; Application.Run(new PrintingExample(text_de_tiparit)); } } }




Reply With Quote