Hi. I'm trying to create a program that prints an invoice with multiple pages continuously. Currently, the program allows to print multiple pages but it is exactly the same content from the first page. How can i print in multiple pages and it continues from the first page?

private void DrawAll(System.Drawing.Printing.PrintPageEventArgs e, int controlnum)
    {
        //RectangleF srcRect = new Rectangle(0, 0, this.Width,
        //    LargerImage.Height);

        Graphics g = e.Graphics;

        //e.HasMorePages = true;

        RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width,
            BackgroundImage.Height);


        int nWidth = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width;
        int nHeight = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height;
        RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);

        g.DrawImage(this.BackgroundImage, destRect, srcRect, GraphicsUnit.Pixel);
        //          g.DrawImage(this.LargerImage, destRect, srcRect, GraphicsUnit.Pixel);

        float scalex = destRect.Width/this.BackgroundImage.Width;
        float scaley = destRect.Height/this.BackgroundImage.Height;

        Pen aPen = new Pen(Brushes.Black, 1);

        float ypos = 0;
        string name = "HATLAPA";
        string name2 = "A S I A  P A C I F I C  P T E  L T D";
        string CompanyAddress1 = "25 International Business Park, #02-25 German Centre";
        string CompanyAddress2 = "Singapore 609916. Tel:(65) 65628088 Fax:(65)65628099";
        Font f = new Font("Arial Black", 24);
        Font f2 = new Font("Times New Roman", 14,FontStyle.Bold);
        Font f3 = new Font("Arial",10);

        g.DrawString(name, f, Brushes.Black, scalex + 320, scaley - 10 , new StringFormat());
        g.DrawString(name2, f2, Brushes.Black, scalex + 266, scaley + 26, new StringFormat());
        g.DrawString(CompanyAddress1, f3, Brushes.Black, scalex + 232, scaley + 56, new StringFormat());
        g.DrawString(CompanyAddress2, f3, Brushes.Black, scalex + 227, scaley + 75, new StringFormat());


        for (int i = controlnum; i < this.Controls.Count; i++)
        {
            // draw logo
            //if (Controls[i].GetType() == this.pictureBox1.GetType())
            //{
            //    if (pictureBox1.Image != null)
            //    {
            //        GraphicsUnit gu = GraphicsUnit.Pixel;
            //        RectangleF scaledRectangle = GetScaledRectangle(scalex, scaley, pictureBox1.Bounds);
            //        Image myImage = (Image)pictureBox1.Image.Clone();
            //        g.DrawImage(myImage, scaledRectangle, pictureBox1.Image.GetBounds(ref gu), GraphicsUnit.Pixel);
            //    }
            //}

            // print edit box control contents
            if (Controls[i].GetType() == this.textBox1.GetType())
            {
                if (!ControlIsListViewEdit(i)) // skip these
                {
                    TextBox theText = (TextBox)Controls[i];
                    if (theText.Name == "SubtotalTextBox" )
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j+1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 135;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left*scalex + 25, ypos * scaley, new StringFormat());                    
                    }
                    else if (theText.Name == "PercentTextBox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 155;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                    }
                    else if (theText.Name == "SPPTextBox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 175;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                    }

                    else if (theText.Name == "TotalTextBox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 195;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }
                    else if (theText.Name == "paymentTermTextbox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 255;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }

                    else if (theText.Name == "tiemeDeliveryTextbox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 235;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }
                    else if (theText.Name == "validityTextbox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 285;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }

                    else if (theText.Name == "termofPriceTextbox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley +305;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                    }
                    else if (theText.Name == "remarkTextbox")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 325;
                                    break;
                                }
                            }
                        }

                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                    }

                    else
                        g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 35, theText.Bounds.Top * scaley + 115, new StringFormat());                    
                }


            }

        // handle date controls
            if (Controls[i].GetType() == this.TodayPicker.GetType())
            {
                DateTimePicker aPicker = (DateTimePicker)Controls[i];
                g.DrawString(aPicker.Text, aPicker.Font, Brushes.Black, aPicker.Bounds.Left*scalex +35, aPicker.Bounds.Top * scaley + 115, new StringFormat());
            }

            if (Controls[i].GetType() == this.label1.GetType())
            {
                Label l = (Label)Controls[i];
                if (l.Name == "lblSubtotal")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 135;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                }
                else if (l.Name == "lblDiscount")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley +155;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                }

                else if (l.Name == "lblDiscountedPrice")
                {
                        for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 175;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                }
                else if (l.Name == "lblGrandtotal")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 195;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                }
                else if (l.Name == "lblTimeOfDelivery")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 235;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                }

                else if (l.Name == "lblPaymentTerm")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 255;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                }
                else if (l.Name == "lblValidity")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 285;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                }

                else if (l.Name == "lblTermOfPrice")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 305;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                }
                else if (l.Name == "lblRemarks")
                {
                    for (int j = 0; j < listView1.Items.Count; j++)
                    {
                        if (listView1.Items[j].Text == "")
                        {
                            if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                            {
                                ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 325;
                                break;
                            }
                        }
                    }

                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                }



                else
                {
                    g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 35, l.Bounds.Top * scaley + 115, new StringFormat());
                }

            }


            // handle List View Control
            if (Controls[i].GetType() == this.listView1.GetType())
            {
                for (int row = 0; row < listView1.Items.Count; row++)
                {
                    int nextColumnPosition = listView1.Bounds.X;
                    for (int col = 0; col < listView1.Items[row].SubItems.Count; col++)
                    {
                            g.DrawString(listView1.Items[row].SubItems[col].Text, listView1.Items[row].Font, Brushes.Black, (nextColumnPosition + 3)*scalex + 35 , (listView1.Items[row].Bounds.Y + listView1.Bounds.Y)* scaley+115, new StringFormat());
                            nextColumnPosition += listView1.Columns[col].Width;

                    }
                }

            }




//              if (Controls[i].GetType() == this.RetirementPlanCheck.GetType())
//              {
//                  CheckBox theCheck = (CheckBox)Controls[i];
//                  Rectangle aRect = theCheck.Bounds;
//                  g.DrawRectangle(aPen, aRect.Left*scalex, aRect.Top*scaley, aRect.Width*scalex, aRect.Height*scaley);
//                  if (theCheck.Checked)
//                  {
//                      g.DrawString("x", theCheck.Font, Brushes.Black, 
//                          theCheck.Left*scalex + 1, theCheck.Top*scaley + 1, new StringFormat());
//                  }
//              }


            if (i == 10)
            {
                controlnum = i;
                e.HasMorePages = true;

            }
        } // end for loop

        // if ypos near the page margin,
        //   e.hasMorePages = true;



    }

Recommended Answers

All 2 Replies

please put that code between code tags. id like to help you much its hard to read like that

private void DrawAll(System.Drawing.Printing.PrintPageEventArgs e, int controlnum)
		{
            //RectangleF srcRect = new Rectangle(0, 0, this.Width,
            //    LargerImage.Height);

            Graphics g = e.Graphics;

            //e.HasMorePages = true;

            RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width,
                BackgroundImage.Height);


			int nWidth = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width;
			int nHeight = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height;
			RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);
		  
			g.DrawImage(this.BackgroundImage, destRect, srcRect, GraphicsUnit.Pixel);
			//			g.DrawImage(this.LargerImage, destRect, srcRect, GraphicsUnit.Pixel);

			float scalex = destRect.Width/this.BackgroundImage.Width;
			float scaley = destRect.Height/this.BackgroundImage.Height;

			Pen aPen = new Pen(Brushes.Black, 1);

            float ypos = 0;
            string name = "HATLAPA";
            string name2 = "A S I A  P A C I F I C  P T E  L T D";
            string CompanyAddress1 = "25 International Business Park, #02-25 German Centre";
            string CompanyAddress2 = "Singapore 609916. Tel:(65) 65628088 Fax:(65)65628099";
            Font f = new Font("Arial Black", 24);
            Font f2 = new Font("Times New Roman", 14,FontStyle.Bold);
            Font f3 = new Font("Arial",10);

            g.DrawString(name, f, Brushes.Black, scalex + 320, scaley - 10 , new StringFormat());
            g.DrawString(name2, f2, Brushes.Black, scalex + 266, scaley + 26, new StringFormat());
            g.DrawString(CompanyAddress1, f3, Brushes.Black, scalex + 232, scaley + 56, new StringFormat());
            g.DrawString(CompanyAddress2, f3, Brushes.Black, scalex + 227, scaley + 75, new StringFormat());

            
			for (int i = controlnum; i < this.Controls.Count; i++)
			{
				// draw logo
                //if (Controls[i].GetType() == this.pictureBox1.GetType())
                //{
                //    if (pictureBox1.Image != null)
                //    {
                //        GraphicsUnit gu = GraphicsUnit.Pixel;
                //        RectangleF scaledRectangle = GetScaledRectangle(scalex, scaley, pictureBox1.Bounds);
                //        Image myImage = (Image)pictureBox1.Image.Clone();
                //        g.DrawImage(myImage, scaledRectangle, pictureBox1.Image.GetBounds(ref gu), GraphicsUnit.Pixel);
                //    }
                //}

				// print edit box control contents
				if (Controls[i].GetType() == this.textBox1.GetType())
				{
					if (!ControlIsListViewEdit(i)) // skip these
					{
						TextBox theText = (TextBox)Controls[i];
                        if (theText.Name == "SubtotalTextBox" )
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j+1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 135;
                                        break;
                                    }
                                }
                            }
                            
                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left*scalex + 25, ypos * scaley, new StringFormat());                    
                        }
                        else if (theText.Name == "PercentTextBox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 155;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                        }
                        else if (theText.Name == "SPPTextBox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 175;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                        }

                        else if (theText.Name == "TotalTextBox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 195;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                        }
                        else if (theText.Name == "paymentTermTextbox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 255;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                        }

                        else if (theText.Name == "tiemeDeliveryTextbox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 235;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                        }
                        else if (theText.Name == "validityTextbox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 285;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                        }

                        else if (theText.Name == "termofPriceTextbox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley +305;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                        }
                        else if (theText.Name == "remarkTextbox")
                        {
                            for (int j = 0; j < listView1.Items.Count; j++)
                            {
                                if (listView1.Items[j].Text == "")
                                {
                                    if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                    {
                                        ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 325;
                                        break;
                                    }
                                }
                            }

                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                        }

                        else
                            g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex + 35, theText.Bounds.Top * scaley + 115, new StringFormat());                    
                    }


				}

			// handle date controls
				if (Controls[i].GetType() == this.TodayPicker.GetType())
				{
					DateTimePicker aPicker = (DateTimePicker)Controls[i];
					g.DrawString(aPicker.Text, aPicker.Font, Brushes.Black, aPicker.Bounds.Left*scalex +35, aPicker.Bounds.Top * scaley + 115, new StringFormat());
				}

                if (Controls[i].GetType() == this.label1.GetType())
                {
                    Label l = (Label)Controls[i];
                    if (l.Name == "lblSubtotal")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 135;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                    }
                    else if (l.Name == "lblDiscount")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley +155;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                    }

                    else if (l.Name == "lblDiscountedPrice")
                    {
                            for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 175;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                    }
                    else if (l.Name == "lblGrandtotal")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 195;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                    }
                    else if (l.Name == "lblTimeOfDelivery")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 235;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());
                    }

                    else if (l.Name == "lblPaymentTerm")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 255;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());

                    }
                    else if (l.Name == "lblValidity")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 285;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }

                    else if (l.Name == "lblTermOfPrice")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 305;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }
                    else if (l.Name == "lblRemarks")
                    {
                        for (int j = 0; j < listView1.Items.Count; j++)
                        {
                            if (listView1.Items[j].Text == "")
                            {
                                if (j < listView1.Items.Count - 1 && listView1.Items[j + 1].Text == "")
                                {
                                    ypos = (listView1.Items[j].Bounds.Y + listView1.Bounds.Y) * scaley + 325;
                                    break;
                                }
                            }
                        }

                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 25, ypos * scaley, new StringFormat());


                    }



                    else
                    {
                        g.DrawString(l.Text, l.Font, Brushes.Black, l.Bounds.Left * scalex + 35, l.Bounds.Top * scaley + 115, new StringFormat());
                    }

                }


				// handle List View Control
				if (Controls[i].GetType() == this.listView1.GetType())
				{
					for (int row = 0; row < listView1.Items.Count; row++)
					{
						int nextColumnPosition = listView1.Bounds.X;
						for (int col = 0; col < listView1.Items[row].SubItems.Count; col++)
						{
								g.DrawString(listView1.Items[row].SubItems[col].Text, listView1.Items[row].Font, Brushes.Black, (nextColumnPosition + 3)*scalex + 35 , (listView1.Items[row].Bounds.Y + listView1.Bounds.Y)* scaley+115, new StringFormat());
								nextColumnPosition += listView1.Columns[col].Width;

						}
					}
                    
				}




//				if (Controls[i].GetType() == this.RetirementPlanCheck.GetType())
//				{
//					CheckBox theCheck = (CheckBox)Controls[i];
//					Rectangle aRect = theCheck.Bounds;
//					g.DrawRectangle(aPen, aRect.Left*scalex, aRect.Top*scaley, aRect.Width*scalex, aRect.Height*scaley);
//					if (theCheck.Checked)
//					{
//						g.DrawString("x", theCheck.Font, Brushes.Black, 
//							theCheck.Left*scalex + 1, theCheck.Top*scaley + 1, new StringFormat());
//					}
//				}


                if (i == 10)
                {
                    controlnum = i;
                    e.HasMorePages = true;

                }
			} // end for loop
           
            // if ypos near the page margin,
            //   e.hasMorePages = true;



		}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.