Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Im so confuse on how I can put a next page for printing since the other rows cannot make out in the printing.

What I have tried:

      private void pictureBox4_Click(object sender, EventArgs e)
      {
          this.Size = new System.Drawing.Size(1094,645);
          this.SetDesktopLocation(300,200);
          dataGridView1.Size = new Size(264, 498);
          label11.Visible = true;
          panel1.Show();
          pictureBox1.Show();
          pictureBox2.Show();
          pictureBox3.Hide();
          pictureBox3.Location = new Point(1015,145);
          pictureBox4.Hide();
          pictureBox4.Location = new Point(1015,202);
      }

private void pictureBox3_Click(object sender, EventArgs e)
      {
          printPreviewDialog2.ShowDialog();
      }



      private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
      {
          printDocument2.DefaultPageSettings.Landscape = true;
          int heigth = dataGridView1.Height;
          dataGridView1.Height = dataGridView1.RowCount * dataGridView1.RowTemplate.Height * 2;
          bmp = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
          dataGridView1.DrawToBitmap(bmp, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
          dataGridView1.Height = heigth;
          e.Graphics.DrawImage(bmp, 0, 0);

      }
Posted
Updated 17-Feb-20 23:04pm

1 solution

You get a PrintPage event for each page, provided you set the HasMorePages property of the PrintPageEventArgs to true - it defaults to false, so unless your code explicitly sets it, you will only print a single page.
PrintPageEventArgs.HasMorePages Property (System.Drawing.Printing) | Microsoft Docs[^]

So create a class-level private "last printed line" counter, and advance it by a "page" each time you print. If there are more lines to print, then set HasMorePages to true at the end of the event handler, and you will be given another event pretty much immediately for you to print the next page and repeat.
 
Share this answer
 
Comments
Kinneth Custodio Tianchon 18-Feb-20 20:59pm    
I get it. I just can't figure out how to code it.
OriginalGriff 19-Feb-20 1:59am    
Which part? You have all the code, so where is the difficulty?

I'm, not trying to be obtuse or annoying - I genuinely can't see your screen so I have no idea what is easy / difficult for you; what you have tried: we only get exactly what you type to work from.
Kinneth Custodio Tianchon 19-Feb-20 2:43am    
(Which part?)The code inside the class which I will be creating. I'm sorry also I'm not good at coding I am lower than a beginner. That's why I'm having a hard time to figure out what will be the code for that. I've search and read to any answers in the other websites but still confuse on coding it. I am sorry
OriginalGriff 19-Feb-20 3:33am    
If you are "lower than a beginner" then you need to learn the language and how to do things first - you can't just "jump into" complicated stuff, any more than a learner driver can jump straight from "applying for a licence" to driving F1 races!

You can't learn how to do it all properly by asking questions - because your whole approach to how to print data is wrong in this case!
Kinneth Custodio Tianchon 19-Feb-20 4:02am    
Got it. yeah. Thank you

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