从datagridview打印数据

时间:2012-01-26 19:36:43

标签: c# winforms datagridview

我有下一个代码,用于创建一个包含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);

直到这里:

       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);

打印机不打印上述部分(最后2个拉绳)。为什么?

打印机页面尺寸为比例A4(48mmx68mm)

1 个答案:

答案 0 :(得分:0)

为什么你不能使用Crystal报告?或任何其他报告工具,可以在您的情况下更好地服务。

Tutorial for Crystal Reports