引用datagridview1中的单元格值,总是显示索引超出范围,必须为非负值并且小于集合大小。
privatevoidprintDocument1_PrintPage(objectsender,System.Drawing.Printing.PrintPageEve...
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Brush bru = Brushes.Black; int g = dataGridView1.ColumnCount;//获得行数; int h = (g * 5 + 5) / 10;//获得页数; for (int i = 1; i <= h; i++) { e.Graphics.DrawString("NANTONG", new Font(new FontFamily("黑体"), 18), bru, 100, 0); e.Graphics.DrawString(txt_kh.Text, new Font(new FontFamily("黑体"), 18), bru, 60, 35); e.Graphics.DrawString(txt_xh.Text, new Font(new FontFamily("黑体"), 18), bru, 60, 70); e.Graphics.DrawString(dataGridView1.Rows[2 * i - 1].Cells[2].Value.ToString(), new Font(new FontFamily("黑体"), 18), bru, 60, 105); e.Graphics.DrawString(txt_xxh.Text, new Font(new FontFamily("黑体"), 12), bru, 180, 105); e.Graphics.DrawString(txt_gh1.Text + " " + txt_gh2.Text + " " + txt_gh3.Text, new Font(new FontFamily("黑体"), 12), bru, 60, 140); e.Graphics.DrawString(txt_rq.Text, new Font(new FontFamily("黑体"), 12), bru, 200, 140); e.Graphics.DrawString(txt_bz.Text, new Font(new FontFamily("黑体"), 18), bru, 60, 175); if (2 * i - 1 < g) { e.Graphics.DrawString("NANTONG", new Font(new FontFamily("黑体"), 18), bru, 455, 0); e.Graphics.DrawString(txt_kh.Text, new Font(new FontFamily("黑体"), 18), bru, 415, 35); e.Graphics.DrawString(txt_xh.Text, new Font(new FontFamily("黑体"), 18), bru, 415, 70); e.Graphics.DrawString(dataGridView1.Rows[2 * i].Cells[2].Value.ToString(), new Font(new FontFamily("黑体"), 18), bru, 415, 105); e.Graphics.DrawString(txt_xxh.Text, new Font(new FontFamily("黑体"), 12), bru, 535, 105); e.Graphics.DrawString(txt_gh1.Text + " " + txt_gh2.Text + " " + txt_gh3.Text, new Font(new FontFamily("黑体"), 12), bru, 415, 140); e.Graphics.DrawString(txt_rq.Text, new Font(new FontFamily("黑体"), 12), bru, 555, 140); e.Graphics.DrawString(txt_bz.Text, new Font(new FontFamily("黑体"), 18), bru, 415, 175); if (2 * i < g) { e.HasMorePages = true; } else { e.HasMorePages = false; } } } }
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |