从datagridview打印数据
本文关键字:数据 打印 datagridview | 更新日期: 2023-09-27 18:21:36
我有下一个代码,它用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)
为什么不能使用Crystal报表?或任何其他报告工具,在您的情况下可能会更好地服务。
Crystal Reports 教程