【发布时间】:2016-04-02 10:22:10
【问题描述】:
我有一个DataGridView,通过单击打印按钮它显示打印预览,然后通过单击打印按钮它应该打印打印预览内容。
问题是我的DataGridView 内容显示在打印预览中,但是当我将其保存为 xps 文档时。它不显示DataGridView 内容。虽然有页眉和页脚。但只有DataGridView 数据没有打印。
这是打印DataGridView行的代码:
e.Graphics.DrawRectangle(p, new System.Drawing.Rectangle(100, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].FormattedValue.ToString(),
dataGridView1.Font, Brushes.Black, new System.Drawing.Rectangle(90, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(p, new System.Drawing.Rectangle(100, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString(),
dataGridView1.Font, Brushes.Black, new System.Drawing.Rectangle(270, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(p, new System.Drawing.Rectangle(100, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].FormattedValue.ToString(),
dataGridView1.Font, Brushes.Black, new System.Drawing.Rectangle(450, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(p, new System.Drawing.Rectangle(100, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[5].FormattedValue.ToString(),
dataGridView1.Font, Brushes.Black, new System.Drawing.Rectangle(670, height,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
【问题讨论】:
-
除了非常令人费解(为什么不将高度和宽度提取到两个变量中?)代码,如果它确实在预览中显示了内容 似乎 好的。那么,您究竟是如何编写循环和设置文档的呢?你在哪里计算
height? - 另外:不要打电话给DataGridViewaGridView!!这是错误的和令人困惑的......总是用他们的正确名字来称呼事物!是的,需要多输入 四个 个字母。..
标签: c# printing datagridview