0

I have next code which creates a print page with data from datagridview.

Font print10B = new Font("Lucida Console", 10, FontStyle.Bold);
Font print8B = new Font("Arial", 9, FontStyle.Regular);
Font print6B = new Font("Arial", 8, FontStyle.Regular);

e.Graphics.DrawString("   NOTA DE PLATA",print10B,Brushes.Black,10,10);
e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, 70);
e.Graphics.DrawString("Produs   | Cant | Pret | Total ", print8B, Brushes.Black, 10, 100);
int height = 0;
int x = 10;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
  e.Graphics.DrawString(dataGridView1.Rows[i].Cells["DenumireProdus"].Value.ToString(), print6B, Brushes.Black, x, 120+height);
  e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_cantitate"].Value.ToString(), print6B, Brushes.Black, x+70, 120 + height);
  e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_pret"].Value.ToString() , print6B, Brushes.Black, x+105, 120 + height);
  e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produsvaloare"].Value.ToString(), print6B, Brushes.Black, x + 135, 120 + height);
  height += 20;
}
e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, dataGridView1.Height);
e.Graphics.DrawString("Total:  " + textBox1.Text+" RON", print10B, Brushes.Black,40, dataGridView1.Height + 10);

Until here:

e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, dataGridView1.Height);
e.Graphics.DrawString("Total:  " + textBox1.Text+" RON", print10B, Brushes.Black,40, dataGridView1.Height + 10);

The printer does not print the above part ( the last 2 drawstrings). Why?

The printer page size is Proportional A4 (48 mm x 68 mm)

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Emil Dumbazu
  • 662
  • 4
  • 22
  • 37
  • Is it reaching the end of the page? You don't have any logic to make sure it will fit the page. You need to print it across multiple pages if it gets too long. – Trevor Elliott Jan 26 '12 at 22:30
  • See this question: http://stackoverflow.com/questions/8761633/how-to-find-the-actual-printable-area-printdocument – Trevor Elliott Jan 27 '12 at 00:18

1 Answers1

0

This isn't a direct answer to your question, but it may save you a lot of time.

There's code and a component on Codeproject.com that allows you to print/print preview a DataGrid. We use it in a couple of apps, and it's ben a life saver.

http://www.codeproject.com/Articles/36488/DataGridView-Print-Print-Preview-Solution-Part-I

David
  • 72,686
  • 18
  • 132
  • 173