vaquas khan

vaquas khan

  • NA
  • 45
  • 0

Asp.net C# windows application printing issue....

Jan 2 2012 6:36 AM
Dear all,

I need to print a record to dot matrix printer through windows application .....

my code is given below ...

  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))
            {
                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;
        }
        public void Printing()
        {
            string txt="this is my line";

            try
            {
                streamToPrint = new StreamWriter (txt);
                try
                {
                    printFont = new Font("Arial", 10);
                    PrintDocument pd = new PrintDocument();
                    pd.PrintPage += new PrintPageEventHandler
                       (this.pd_PrintPage);
                    pd.Print();
                }
                finally
                {
                    streamToPrint.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

but i want to 50 line per page ,suppose when first time i click the button then its print one line and when again i click the button then print 2 line .....etc  when i reached the 50th record then its allow to printer page break other wise it must be print in same page.

please help me

thanks

Answers (1)