pls help how to use e.hasmorepges..below these code

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {



          //  e.Graphics.DrawLine(Pens.Black, 20, 20, 800, 20);

            e.Graphics.DrawString("INVOICE NO:", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 40, 75);

            string uer = dateTimePicker1.Text ;

            e.Graphics.DrawString(uer, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 500, 75);


            string N = txt1.Text;

            e.Graphics.DrawString(N, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 150, 75);




            e.Graphics.DrawString("Slno", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 40, 140);

            e.Graphics.DrawString("Item Code", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 80, 140);

            e.Graphics.DrawString("Particulars", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 160, 140);


            e.Graphics.DrawString("Units", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 296, 140);

           // e.Graphics.DrawString("VAT", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 296, 140);

            e.Graphics.DrawString("Qty", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 370, 140);

            e.Graphics.DrawString("Unitprice", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black,410, 140);

            e.Graphics.DrawString("Dis", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 495, 140);

            //e.Graphics.DrawString("Vatamt", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black,495, 140);

            e.Graphics.DrawString("Taxes", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 560, 140);

            e.Graphics.DrawString("Price", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 625, 140);

            e.Graphics.DrawString("Total", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black,680, 140);

            e.Graphics.DrawLine(Pens.Black, 20, 160, 800, 160);

            int y = 150;


            for (int j = 0; j < i; j++)
            {
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[0].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 50, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[1].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 95, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[2].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 175, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[3].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 300, y + 25);
                //e.Graphics.DrawString(dataGridView1.Rows[j].Cells[4].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 306, y + 25);

                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[5].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 375, y + 25);

                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[6].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 410, y + 25);

               // e.Graphics.DrawString(dataGridView1.Rows[j].Cells[7].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 500, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[12].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 567, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[9].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 625, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[10].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 686, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[11].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 500, y + 25);

                y += 25; 

            }
            e.Graphics.DrawLine(Pens.Black, 20, y+30, 800, y+30);


            e.Graphics.DrawString("THANK U FOR SHOPPING", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 250, y+250);

            string d = textBox11.Text;

            e.Graphics.DrawString(d, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black,686, y+30);



            string u = textBox12.Text;

            e.Graphics.DrawString(u, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 500, y + 30);


           // e.Graphics.DrawString("Discount", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 600, y + 60);


            string h = label16.Text;

            e.Graphics.DrawString(h, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 100, y + 30);


            string E = textBox6.Text;

            e.Graphics.DrawString(E, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 375, y+30);

            e.Graphics.DrawString("Non Taxable:", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 40, y + 120);


            string r = label31.Text;

            e.Graphics.DrawString(r, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 150, y + 120);

            string t = label23.Text;

            e.Graphics.DrawString(t, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black,150, y + 90);
            string trt = textBox13.Text;

            e.Graphics.DrawString(trt, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 686, y + 60);
            e.Graphics.DrawString(" Less Cash Discount", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 100, y + 60);

            e.Graphics.DrawString(" Taxable Rs:", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 40, y+90);

            //string z= textBox11.Text;

            //e.Graphics.DrawString(z, new Font("Times New Roman", 13, FontStyle.Bold), Brushes.Black, 686, y + 95);





            e.Graphics.DrawString("NET   TOTAL --Rs", new Font("Times New Roman", 15, FontStyle.Regular), Brushes.Black, 270, y + 150);


      string ww = textBox16.Text;

      e.Graphics.DrawString(ww + "/- (Rounded)", new Font("Times New Roman", 14, FontStyle.Regular), Brushes.Black, 450, y + 150);




            e.Graphics.DrawLine(Pens.Black, 20, y+175, 800, y+175);

            e.Graphics.DrawString("currency...Rs", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 50, y + 175);


            string wl = textBox11.Text;

            e.Graphics.DrawString(wl + "/-", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 135, y + 175);


            e.Graphics.DrawString("Balance", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 210, y + 175);


            string wlk = textBox17.Text;

            e.Graphics.DrawString(wlk, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 265, y + 175);

        }

Edited 4 Years Ago by wolverinnas: code repeating

int i = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
e.Graphics.DrawString("INVOICE NO:", new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 40, 75);


            string N = txt1.Text;

            e.Graphics.DrawString(N, new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 150, 75);





            int y = 150;


            for (int j = 0; j < i; j++)
            {
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[0].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 50, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[1].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 95, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[2].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 175, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[3].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 300, y + 25);
                // e.Graphics.DrawString(dataGridView1.Rows[j].Cells[4].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 306, y + 25);

                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[5].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 375, y + 25);

                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[6].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 410, y + 25);

                //e.Graphics.DrawString(dataGridView1.Rows[j].Cells[7].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 500, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[12].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 567, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[9].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 625, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[10].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 686, y + 25);
                e.Graphics.DrawString(dataGridView1.Rows[j].Cells[11].Value.ToString(), new Font("Times New Roman", 11, FontStyle.Regular), Brushes.Black, 500, y + 25);
                y += 25;

            }
e.hasmorepages=true;

            string d = textBox11.Text;

            e.Graphics.DrawString(d, new Font("Times New Roman", 11, FontStyle.Bold), Brushes.Black, 686, y + 30);
e.hasmorepages=false;

}
This article has been dead for over six months. Start a new discussion instead.